There are probably a dozen different answers to this question as you are not being very precise. Yet, this is one possible answer:
Option Explicit
Public Sub Test()
Dim lngRow As Long
For lngRow = 1 To 4
Worksheets("Sheet1").Cells(lngRow, 1).Formula = "=row()"
Worksheets("Sheet1").Cells(lngRow + lngRow - 1, 2).Formula = "=A" & lngRow
Worksheets("Sheet1").Cells(lngRow + lngRow, 2).Formula = "=A" & lngRow
Next lngRow
End Sub
I did it like this:
Private Sub CommandButton1_Click() Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Dim c As Range
For Each c In ws.UsedRange.Columns("A").Cells
ActiveSheet.Cells(c.Value, 1).Formula = "=row()"
ActiveSheet.Cells(c.Value + c.Value - 1, 2).Formula = "=A" & c.Value
ActiveSheet.Cells(c.Value + c.Value, 2).Formula = "=A" & c.Value
Next c Next ws
End Sub
But if I put a non-numeric value in the first column it does not work. What I am missing?
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.