VBA: Change VBA script cell reference

Batteredburrito

New Member
Joined
Jul 31, 2018
Messages
15
Hi, i have the following

Code:
Sub InsertNewBill_Click()

Dim rngCopy As Range
Dim rngPaste As Range
Dim clearCell As Range

If i < 31 Then
 i = 31
 Cells(30, 1) = i
 i = Cells(30, 1) + 1
     Cells(30, 1) = i
     
     Else
 i = Cells(30, 1) + 1
 Cells(30, 1) = i
End If

ActiveSheet.Range("A" & i & ":AD" & i).Insert

Set rngPaste = Range("A" & i & ":AD" & i)
Set rngCopy = ActiveSheet.Range("A" & i - 1 & ":AD" & i - 1)

rngCopy.Copy
rngPaste.PasteSpecial Paste:=xlPasteAll

With ActiveSheet
    Cells(i, 1).Clear
End With

Call DeleteTickBoxes_Click

End Sub

It inserts a new line based on the Cell value of A30 (referenced as Cell(i,1) or Cell(30,1)
I need to change this to reference the sheet "Essential Info" and Cell G17.
I have learnt how to define ranges but altering a Cell Reference seems a little more tricky
I appreciate the help with this.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Resolved this with the following code alterations:

Code:
Sub InsertNewBill_Click()

Dim rngCopy As Range
Dim rngPaste As Range
Dim clearCell As Range

If i < 31 Then
 i = 31
[B]Sheets("Essential Info").Range("G17").Value[/B] = i
 i = [B]Sheets("Essential Info").Range("G17").Value[/B] + 1
     [B]Sheets("Essential Info").Range("G17").Value[/B] = i
     
     Else
 i = [B]Sheets("Essential Info").Range("G17").Value[/B] + 1
 [B]Sheets("Essential Info").Range("G17").Value[/B] = i
End If

ActiveSheet.Range("A" & i & ":AD" & i).Insert

Set rngPaste = Range("A" & i & ":AD" & i)
Set rngCopy = ActiveSheet.Range("A" & i - 1 & ":AD" & i - 1)

rngCopy.Copy
rngPaste.PasteSpecial Paste:=xlPasteAll

Call DeleteTickBoxes_Click

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,989
Messages
6,175,804
Members
452,670
Latest member
nogarth

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