Call a range with a Row that is a variable

riedyp

Board Regular
Joined
Feb 13, 2020
Messages
88
Office Version
  1. 365
Platform
  1. Windows
Hello,

I want to call a Range that will be in my variable row "LastRow" and span from column B to column I. I have tried several different methods and cant seem to get the syntax correct. Attached is my last "hail mary" of an attempt that ultimately failed. Thank you.
VBA Code:
Private Sub CommandButton1_Click()
LastRow = Sheet5.Cells(1000, 2).End(xlUp).Row + 2 'Finds the last edited row and then adds two rows
LastNumber = Sheet5.Cells(1000, 1).End(xlUp).Value + 1 'Finds the last question number and adds 1
 Sheet5.Cells(LastRow, 1).Select ' Selects LastRow in the first Column
    ActiveCell.Formula = LastNumber ' Gives it LastNumber
Sheet5.Range(BLastRow,ILastRow)
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
What do you want to do with the range?
 
Upvote 0
I am going to merge these cells and give them a new color.
 
Upvote 0
I would strongly recommend against merging them. Merged cells are an abomination & should be avoided like the plague.
They will only cause you problems later on.
This will change the fill colour
VBA Code:
Private Sub CommandButton1_Click()
   LastRow = Sheet5.Cells(1000, 2).End(xlUp).Row + 2 'Finds the last edited row and then adds two rows
   LastNumber = Sheet5.Cells(1000, 1).End(xlUp).Value + 1 'Finds the last question number and adds 1
   Sheet5.Cells(LastRow, 1).Value = LastNumber ' Gives it LastNumber
   Sheet5.Range("B" & LastRow).Resize(, 8).Interior.Color = 45678
End Sub
 
Upvote 0
I would strongly recommend against merging them. Merged cells are an abomination & should be avoided like the plague.
They will only cause you problems later on.
This will change the fill colour
VBA Code:
Private Sub CommandButton1_Click()
   LastRow = Sheet5.Cells(1000, 2).End(xlUp).Row + 2 'Finds the last edited row and then adds two rows
   LastNumber = Sheet5.Cells(1000, 1).End(xlUp).Value + 1 'Finds the last question number and adds 1
   Sheet5.Cells(LastRow, 1).Value = LastNumber ' Gives it LastNumber
   Sheet5.Range("B" & LastRow).Resize(, 8).Interior.Color = 45678
End Sub
Haha alright I will try to stay away from it, I can definitely see how it could become an annoyance. Your solution worked, Thank you!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,391
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top