Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

excel - VBA Trying to print values into the last row

I'm using this code (in conjunction with code that calculates the variables using ranges in a different sheet - these calculations are working perfectly). I'm then using this "with statement" to swap to the sheet I want to print the values into.

I'm trying to print the values into the first blank row (I've checked and the row is blank). However, no information is filling out into the cells - they remain blank.

 With Sheets("Reconciliation")
                            Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = E
                            Range("A" & Rows.Count).End(xlUp).Offset(0, 1).Value = Str
                            Range("A" & Rows.Count).End(xlUp).Offset(0, 2).Value = Min
                            Range("A" & Rows.Count).End(xlUp).Offset(0, 3).Value = Max
                            Range("A" & Rows.Count).End(xlUp).Offset(0, 5).Value = Sea
                            Range("A" & Rows.Count).End(xlUp).Offset(0, 6).Value = Mat
                        End With
question from:https://stackoverflow.com/questions/65837450/vba-trying-to-print-values-into-the-last-row

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this for simplicity:

Dim lastRow as Long
With Sheets("Reconciliation")
    lastRow = .Range("A1").Cells(.Rows.Count,1).End(xlUp).Row
    .Range("A1").Cells(lastRow+1,1).Value = E
    .Range("A1").Cells(lastRow+1,2).Value = Str
    .Range("A1").Cells(lastRow+1,3).Value = Min
    .Range("A1").Cells(lastRow+1,4).Value = Max
    .Range("A1").Cells(lastRow+1,6).Value = Sea
    .Range("A1").Cells(lastRow+1,7).Value = Mat
End With

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...