2015-09-25 43 views
0

我試圖以線性方式將數據從「詳細信息」表存儲到不同列中的字​​符串到每個行的不同字符串,然後將字符串在名爲「輸出」的其他紙張的單元中有相同的值51次。運行時錯誤'1004'無法設置範圍的文本屬性

Option Explicit 

Sub Arrange() 
Dim FinalRow, FinalRow1 As Long 
Dim ws, wr As Worksheet 
Dim strCN, strAdd, strCity, strState, strZip, strPhone, strWeb As String 
Application.ScreenUpdating = False 
Dim i, j As Long 


Set ws = Sheets("details") 
FinalRow = ws.Range("A900000").End(xlUp).Row 

For j = 2 To FinalRow 

    strCN = Cells(j, "A") 
    strAdd = Cells(j, "H") 
    strCity = Cells(j, "I") 
    strState = Cells(j, "J") 
    strZip = Cells(j, "K") 
    strPhone = Cells(j, "R") 
    strWeb = Cells(j, "U") 

    Set wr = Sheets("output") 
    FinalRow1 = wr.Range("A900000").End(xlUp).Row 
    For i = FinalRow1 To FinalRow1 + 51 
     With Sheets("output") 
      Cells(i, "A").Text = strCN  'Error Line 
      Cells(i, "B").Text = strAdd 
      Cells(i, "C").Text = strCity 
      Cells(i, "D").Text = strState 
      Cells(i, "E").Text = strZip 
      Cells(i, "F").Text = strPhone 
      Cells(i, "G").Text = strWeb 
     End With 
    Next i 
Next j 

End Sub 
+2

更改'.text'到'.value' –

+0

已經沒有給我下標超出範圍錯誤 –

+0

當它打破的,什麼是「我」的價值?什麼是strCN的價值? –

回答

1

正如我們上面的談話。我已經做出了我所建議的改變。

最後一個問題是未調用詳細信息表,如果其他表在查看空單元格時處於活動狀態。

Dim FinalRow, FinalRow1 As Long 
Dim ws, wr As Worksheet 
Dim strCN, strAdd, strCity, strState, strZip, strPhone, strWeb As String 
Application.ScreenUpdating = False 
Dim i, j As Long 


Set ws = Sheets("details") 
FinalRow = ws.Range("A900000").End(xlUp).Row 

For j = 2 To FinalRow 
    With ws 
     strCN = .Cells(j, "A") 
     strAdd = .Cells(j, "H") 
     strCity = .Cells(j, "I") 
     strState = .Cells(j, "J") 
     strZip = .Cells(j, "K") 
     strPhone = .Cells(j, "R") 
     strWeb = .Cells(j, "U") 
    End With 
    Set wr = Sheets("output") 
    FinalRow1 = wr.Range("A900000").End(xlUp).Row 
    For i = FinalRow1 To FinalRow1 + 51 
     With Sheets("output") 
      .Cells(i, "A").Value = strCN  'Error Line 
      .Cells(i, "B").Value = strAdd 
      .Cells(i, "C").Value = strCity 
      .Cells(i, "D").Value = strState 
      .Cells(i, "E").Value = strZip 
      .Cells(i, "F").Value = strPhone 
      .Cells(i, "G").Value = strWeb 
     End With 
    Next i 
Next j 
Application.ScreenUpdating = True 
+0

你介意共享你的工作文件通過Dropbox或其他的東西,請出於某種原因,我不能讓它工作 –

+0

只是給我發電子郵件[email protected],我會發送給你。 –

相關問題