Fix code - help!

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,493
Office Version
  1. 2016
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

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,890
Office Version
  1. 365
Platform
  1. Windows
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
 

Weaver

Well-known Member
Joined
Sep 10, 2008
Messages
5,196
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
 

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,493
Office Version
  1. 2016
Platform
  1. Windows
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
 

Forum statistics

Threads
1,141,734
Messages
5,708,166
Members
421,549
Latest member
Dtcfire

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
Top