proper syntax for With Rng/Evaluate?

ilcaa

Well-known Member
Joined
May 25, 2005
Messages
751
Office Version
  1. 365
Platform
  1. Windows
i have a range(1000 rows) that i want to apply a change to. Its basically taking a variable and placing at the front of each string along with a comma. here is a before and after

6 of 1998 3-0-1 100.00% 14-18-2 43.75%
36, 6 of 1998 3-0-1 100.00% 14-18-2 43.75%

variable was 36 in this case. I though it was simple enough, but i get a 'Type MisMatch' error.

What is proper syntax, would EVALUATE help out?? thanks


Code:
Formula = 36

With Rng
    .Value = Formula & "," & .Value
End With
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hello,

No Evaluate would not help ...

You can test following
Code:
Sub Check()
    Dim rng As Range
    Dim formula As String
    formula = 36
    Set rng = ActiveCell
    With rng
        .Value = formula & "," & .Value
    End With
End Sub

Hope this will help
 
Upvote 0
I think you are also asking for problems, If you are assigning a number to a variable called "formula"
Call it n, or x, or anything but using the word formula.
 
Upvote 0
Code:
Dim f$: f = "36, "
Dim rng As Range: Set rng = [A1:A8]
rng = Application.Evaluate("concatenate(" & f & """, ""," & rng.Address & ")")
 
Upvote 0
Hello,

No Evaluate would not help ...

You can test following
Code:
Sub Check()
    Dim rng As Range
    Dim formula As String
    formula = 36
    Set rng = ActiveCell
    With rng
        .Value = formula & "," & .Value
    End With
End Sub

Hope this will help

thanks. if i use this on a single cell it works fine. if i use this on a range of cells, i get the same mismatch error. if you notice my original post, it has the same formula,
Code:
with rng
   .value = formula & "," & .value
end with

my range is 1000 rows and i need to adds this variable to each row, I do not want to do a loop and trying to find the right syntax for With Range.
 
Upvote 0
How about
Code:
Sub ilcaa()
   With Range("A1", Range("A" & Rows.Count).End(xlUp))
      .Value = Evaluate("If({1},""36, ""&" & .Address & ")")
   End With
End Sub
 
Upvote 0
How about
Code:
Sub ilcaa()
   With Range("A1", Range("A" & Rows.Count).End(xlUp))
      .Value = Evaluate("If({1},""36, ""&" & .Address & ")")
   End With
End Sub

thanks mr fluffer, that worked.
 
Upvote 0
i had a question, this symtax is quite confusing between all the quotes. if my value 36 is actually a variable named 'strategy', how would i incorporate that into this evaluate? i tried several ways but get the #NAME ? error
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
How about
Code:
Sub ilcaa()
   With Range("A1", Range("A" & Rows.Count).End(xlUp))
      .Value = Evaluate("If({1},""36, ""&" & .Address & ")")
   End With
End Sub

to be more speciifc and follow up on my reply..

instead of a hard coded 36.
strategy = 36

how would the evaluate look then (ive tried multiple ways but between all the quotes and & ai cant figure out the syntax
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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