Excelを読込、文字列が含まれるならならそのままもってきて数値なら数値?半角英数字として持ってきたいです。
現状はすべて文字列になってしまいます。
コメントアウトしてるところはいろいろ試したけど、出来なかった痕跡です。。。
VBA
1Private Sub openPS(fp As String) 2 '職員マスタ 3 Dim i As Long 4 Dim r As Long 5 Dim c As Long 6 Dim iLine As Long 7 Dim wb As Workbook 8 Dim sh As Worksheet 9 Dim sData(9) As String 10 Dim Err As Long 11 12 Set wb = Workbooks.Open(Filename:=fp, ReadOnly:=True) 13 Set sh = wb.Worksheets(1) 14 iLine = 14 15 r = sh.Cells(sh.Rows.Count, 5).End(xlUp).Row 16 17 For i = 2 To r 18' If sh.Cells(i, 6) <> "" Then 19 sData(0) = CLng(sh.Cells(i, 5).Value) 20 sData(1) = sh.Cells(i, 6).Value 21 sData(2) = sh.Cells(i, 7).Value 22 sData(3) = sh.Cells(i, 8).Value 23 sData(4) = sh.Cells(i, 9).Value 24 sData(5) = sh.Cells(i, 12).Value 25 sData(6) = sh.Cells(i, 13).Value 26 sData(7) = sh.Cells(i, 14).Value 27 sData(8) = sh.Cells(i, 15).Value 28 sData(9) = sh.Cells(i, 17).Value 29' For c = 1 To Len(sData(0)) 30' If Mid(sData(0), c, 1) Like "[A-z]" Or Mid(sData(0), c, 1) Like "[0-9]" Then 31' Me.Cells(iLine, 3).Value = Me.Cells(iLine, 3) & StrConv(Mid(Trim$(sData(0)), c, 1), vbNarrow) 32' Else 33' Me.Cells(iLine, 3).Value = Me.Cells(iLine, 3) & Mid(Trim$(sData(0)), c, 1) '職員コード 34' End If 35' Next 36' sData(0) = CLng(sData(0)) 37 Me.Cells(iLine, 3).Value = Trim$(StrConv(sData(0), vbNarrow)) '職員コード 38 Me.Cells(iLine, 4).Value = Trim$(sData(1)) '漢字氏名 39 Me.Cells(iLine, 5).Value = Trim$(StrConv(sData(2), vbWide)) 'カナ 40 Me.Cells(iLine, 6).Value = Trim$(StrConv(sData(3), vbNarrow)) '性別 41 Me.Cells(iLine, 7).Value = Format(Trim$(sData(4)), "yyyymm") '入庫年月 42 Me.Cells(iLine, 8).Value = Trim$(StrConv(sData(5), vbNarrow)) '郵便番号 43 Me.Cells(iLine, 9).Value = Trim$(sData(6)) '住所1 44 Me.Cells(iLine, 10).Value = Trim$(sData(7)) '住所2 45 Me.Cells(iLine, 11).Value = Trim$(sData(8)) '住所3 46 Me.Cells(iLine, 12).Value = Trim$(sData(9)) '連絡欄 47 iLine = iLine + 1 48 49 50 Next 51 Me.Range("C13:L" & CStr(iLine - 1)).Borders.LineStyle = xlContinuous 52 wb.Close 53' r = Me.Cells(Me.Rows.Count, 3).End(xlUp).Row 54' For i = 14 To r 55' Me.Cells(iLine, 3) = CLng(Me.Cells(iLine, 3)) 56' Next 57 58 59 60 Call ErrCheck 61 62 63End Sub
回答5件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/09/13 10:28