Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I extend a very worthy thanks to you Rick!! I saved your final post!!
Thanks to everyone!! Regards, Ryan--- -- RyGuy "Rick Rothstein (MVP - VB)" wrote: Yep, triple quotes... but it not really that hard to see why. Consider this... **all** String constants (non-variable text) **must** have quote marks around it. This you already know. For example... SomeVariable = "I am a String constant" You have to surround the text with quote marks so VB will not it is a String constant. Now, to put an actual quote mark symbol inside of a String constant, you place two of them next to each other. So, consider this String constant... SomeVariable = "This symbol "" is a quote mark" If you execute this statement, SomeVariable will contain this... This symbol " is a quote mark I think you already probably knew this. Okay, now, back to this statement... SomeVariable = "This symbol "" is a quote mark" Remove the text in front of the double quote marks.... SomeVariable = """ is a quote mark" Notice there are three quote marks next to each other at the beginning of the String constant; and notice I have not changed any rule... all I did is remove some text from a statement you already knew worked. If you execute this statement, the following is what is assigned to the variable... " is a quote mark Similarly, we could have removed the text after the double quote marks instead. If we did that, this is what would have resulted... SomeVariable = "This symbol """ and, again, we have three quote marks next to each other. The rule to be garnered from this is... to have a leading quote mark in a String, the String will start with three quote marks; to have a trailing quote mark in a String, the String will end with three quote marks. Okay, that takes care of your "question"; but let's take this one step further. Going back to the original assignment, namely.... SomeVariable = "This symbol "" is a quote mark" This time, instead of removing only the text in front of the double quote marks, or the text after it, let's remove the text from both sides. Doing that, we are left with this... SomeVariable = """" Notice we have four quote marks next to each other! What prints out? Simply the " that was in the original text when there was other text around it. We removed the text and all that was left is what was needed to produce a single quote mark. That is why you will see four quote marks strung together in a concatenation in order to produce a single quote mark at the give location. The outer two quote marks are required because it is a String constant and the inner two quote marks are how a single quote mark is placed within a String constant. Rick "ryguy7272" wrote in message ... TRIPLE QUOTES!!!????? It's going to be a long time before I have MVP after my name, and I don't think I will have one of those silver circle by name for a while either... Thanks for everything guys!! Problem resolved!! Ryan--- -- RyGuy "Rick Rothstein (MVP - VB)" wrote: If, as you said in one of your other posts, that this... C.Offset(, 19).Formula = "=(IF(RC[-19]=" & Chng & _ " ,RC[-17],0)+IF(RC[-15]=" & _ Chng & ",RC[-14],0))*RC[-2]" gives you everything you need except for the quotes around the name, then change it to this... C.Offset(, 19).Formula = "=(IF(RC[-19]=""" & Chng & _ """ ,RC[-17],0)+IF(RC[-15]=""" & _ Chng & """,RC[-14],0))*RC[-2]" Note that I made use of line continuation characters in order to control how the newsreader word-wrapped the code lines. Rick "ryguy7272" wrote in message ... Thanks for the look Rick. I tried it both ways: Chng = .Range("F2") and: Chng = Range("F2").Value The results were the same with both methods. So much for that statement about this being 'simple' in my original post. Eyes rolling now... Each time I get: =(IF(F2=Frank,H2,0)+IF(J2=Frank,K2,0))*W2 What I really want is: =(IF(F2="Frank",H2,0)+IF(J2="Frank",K2,0))*W2 Any other thought on this??? -- RyGuy "Rick Rothstein (MVP - VB)" wrote: Since you are inside a With/End With block, I **think** you may want to put a dot in front of the Range reference so you pick up the Range from the currently being looked at worksheet... Chng = .Range("F2") I am presuming here you are trying to get to the Value property of F2 (I hate relying on default properties the way I think you are doing as it makes the code much harder to read when debugging) and not trying to Set a reference to the Range itself (which would still need the leading dot) Rick "ryguy7272" wrote in message ... I have to use, what I thought was, a simple variable input, but it's turning out to be not so simple. Basically I loop through all sheets in a book, as long as the sheets < "Sheet1". Then do some basic formatting and some simple math. Everything works fine except for this part: Chng = Range("F2") and this part: c.Offset(, 19).Value = "=(IF(RC[-20]="&Chng&",RC[-18],0)+IF(RC[-15]="&Chng&",RC[-14],0))*RC[-3]" I have names in column F of each sheet, which are all the same on each sheet, but different names are on different sheets. All I need to do is figure out the value in F2 on each sheet and use that in my IF function. I thought I could just assign the value in F2 to the variable Chng and then just use that variable in my IF function. Excel has other thoughts and it is telling me that I can't do that. Why? All code below: Sub Math() Dim lastRow As Long Dim c As Variant Dim sh As Worksheet Dim myA As Range Dim lastYRow As Long Dim sumRng As Range Dim Tot As Double Dim Chng As Variant For Each sh In Worksheets If LCase(sh.Name) < LCase("Sheet1") Then sh.Activate With sh .Rows(1).Font.Bold = True Chng = Range("F2") lastRow = .Cells(.Rows.Count, "F").End(xlUp).Row For Each c In .Range("F2:F" & lastRow) If c.Value < "" Then c.Offset(, 19).Value = "=(IF(RC[-20]="&Chng&",RC[-18],0)+IF(RC[-15]="&Chng&",RC[-14],0))*RC[-3]" End If Next c lastYRow = .Cells(.Rows.Count, "Y").End(xlUp).Row Set sumRng = .Range("Y2:Y" & lastYRow) Tot = Application.WorksheetFunction.Sum(sumRng) 'MsgBox Tot .Cells(lastRow + 1, "Y").Value = Tot '.Rows(2).Delete End With End If Next sh End Sub Any help is appreciated. Regards, Ryan-- -- RyGuy |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Input box and assigning to a variable. | Excel Programming | |||
With QUERY how to input a variable | Excel Discussion (Misc queries) | |||
How Macro Ask for Variable Input? | Excel Programming | |||
variable/Input box problem | Excel Programming | |||
Input box with variable | Excel Programming |