Fix code - help!

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,602
Office Version
  1. 365
Platform
  1. Windows
Hi all

I'm trying to paste the value of B3 in weekly perf sheet into next available row in column x of graphs sheet.
The pasted value should also be pasted with the following formula
Code:
=RIGHT('weekly perf'!B3,FIND("-",'weekly perf'!B3)-2)
but not being any good at VB I am stuck!

The code I have tried to write so far is as follows, but it doesn't do the job..
Code:
Sub Ant()
    Sheets("weekly perf").Select
    Range("B3").Select
    Sheets("graphs").Select
    ' Find the last row of data
    FinalRow = Range("X65536").End(xlUp).Row

Selection.Formula "=RIGHT('weekly perf'!B3,FIND(" - ",'weekly perf'!B3)-2)"
End Sub

any help to fix this would be apreciated

thanks
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try:
Code:
Sub Ant()
Dim FinalRow as Long
Dim myValue as Variant
 
myValue = Sheets("weekly perf").Range("B3")
Sheets("graphs").Select
' Find the last row of data
FinalRow = Range("X" & Rows.Count).End(xlUp).Row
With Range("X" & FinalRow)
  .Formula "=RIGHT(" & myValue & ",FIND("" - ""," & myValue & ")-2)"
End With
End Sub
 
Upvote 0
Which sheet/range do you need the formula in?

You select a cell in 'weekly perf' and then select the 'graphs' sheet

try

Code:
Sheets("weekly perf").Range("B3")
  .formula = "=RIGHT('weekly perf'!B3,FIND(" - ",'weekly perf'!B3)-2)"
  .value = .value
end with
 
Upvote 0
Hi guys

Thanks for all your replies, however, I'm still a little confused as code still doesn't quite work

Code:
Sub Ant()
Dim FinalRow As Long
Dim myValue As Variant
 
myValue = Sheets("weekly perf").Range("B3")
Sheets("graphs").Select
' Find the last row of data
FinalRow = Range("X" & Rows.Count).End(xlUp).Row
With Range("X" & FinalRow)
  .Formula = "=RIGHT(" & myValue & ",FIND("" - ""," & myValue & ")-2)"
End With
End Sub
this gives error on the
Code:
.Formula = "=RIGHT(" & myValue & ",FIND("" - ""," & myValue & ")-2)"

as I said originally, I want the value of cell B3 from weekly perfs sheet copied and then pasted into next available row of column X on the graphs sheet.
When it is pasted the followinf formula is added...

Code:
=RIGHT('weekly perf'!B3,FIND("-",'weekly perf'!B3)-2)

sorry if I've confused anyone and again hope you can help

regards
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,243
Members
448,555
Latest member
RobertJones1986

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