简体   繁体   中英

Finding lastrow of different range in same worksheet

I am required to do an automation task that copy tables in linux to excel, then populating graphs for tracking. The task is almost fully automated but i still need to do some manual jobs in Excel.

Supposedly in the SUMMARY(1) worksheet, I have 10 different modes and SUMMARY (2) worksheet with 10 different modes. Every week, the data for each mode will be updated automatically from col F:K. I already did that part automatically using VBA. However, i need to write manually for col A:D of each modes where:

  • col A : O means occupied and E means empty
  • col B : Week's number
  • col C : Date with specific format, not the usual
  • col D : Database name

The SUMMARY worksheet that consists of 10 modes is from A1:S51 (mode1), A52:S:101 (mode2), and so on until the last most A452:S501 (mode 10) where all the modes' range is 50 cells.

I already prompt user for input and stored in variable, but how do i paste the value on the next line of each mode. For example, i already update from W1 till W4, when user prompt input for WW5, the values will be stored in the next line after lastrow of each mode.

This is the example on how it looks like for mode 1 and 2. The rest of the modes are probably will be followed after mode2.

发明内容(1)

This is my current code where when user input values, it will paste to the first line of each mode:

Private Sub CommandButton1_Click()

Dim d As Variant
Dim w As Variant
Dim daymonth As Variant
Dim data As Variant
Dim i As Integer

d = InputBox("Enter the D:")
w = InputBox("Enter the Week:")
daymonth = InputBox("Enter the date:")
data = InputBox("Enter the database name:")
For i = 2 To 501 Step 50
     Cells(i, 1).Value = d
     Cells(i, 2).Value = w
     Cells(i, 3).Value = daymonth
     Cells(i, 4).Value = data

Next i

End Sub

Here is a code that can do the trick. Before running the code if there is any mode which has less than 2 rows of data this code will work incorrectly. In that case you will need to modify it based on how you want to handle it.

wk_no = InputBox("Enter Week")

For i = 1 To 2 ' Iterating through sheets
    For j = 2 To 452 Step 50 'Iterating through the rows
        Sheets(i).Range("B" & Trim(Str(j))).End(xlDown).Offset(1, 0).Value = wk_no
    Next j
Next i

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM