I am trying to store data from "details" sheet into strings from different columns to different strings for every row in a linear manner and then assign the strings the same value 51 times in Cells of other sheet named "output".
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
As per our conversation above. I have made the changes I suggested.
The last problem was that the details sheet was not being called and if the other sheet was active at the time it was looking at empty cells.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.