Ironically, it never actually occured to me to use Chr(34) for putting in quotes. I've also doubled up to get them. Works with other languages like SQL too, so it can't be all bad.![]()
Ironically, it never actually occured to me to use Chr(34) for putting in quotes. I've also doubled up to get them. Works with other languages like SQL too, so it can't be all bad.![]()
Ken Puls, CMA, MS MVP (Excel)
Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter
If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.
I started out by always using Chr(34), but switched to embedded quotes as I just didn't like it. If you don't like embedded quotes, a better way in my view is to define a quote constant and use that.
Obvious and meaningful. This was my interim stage until I went fully embedded.Code:Const quote As String = """"Worksheets("Totals").Cells(cellCount + 10, 5).Formula = _ "=COUNTIF('" & cellCount & "'!G:G," & quote & "H" & quote & ")"
Before I knew any better, I got very familiar with the Chr() function. You see I didn't know there was a very simple way to refer to cells by number and thought it had to be done by letter.
This is the code I was using to find the last column on a sheet I had, it makes me cringe to look at now. Also it is only good from A to ZZ.
oh how easier it is to do something likeCode:'reset variables to figure how many columns there are for sorting colCnt = 75 ' start on col K colCnt2 = 64 colNameMax = Chr(colCnt) 'count how many columns to sort Do While IsEmpty(Worksheets(sheetName(sheetCnt)).Range(colNameMax & "1")) = False Worksheets(sheetName(sheetCnt)).Range(colNameMax & "3").Formula = "=sum(" & colNameMax & "9:" & colNameMax & totalRowCnt(sheetCnt) & ")" 'colCnt = colCnt + 1 If colCnt = 90 Then colCnt = 65 colCnt2 = colCnt2 + 1 colNameMax = Chr(colCnt2) & Chr(colCnt) ElseIf colCnt2 > 64 Then 'colCnt2 = colCnt2 + 1 colCnt = colCnt + 1 colNameMax = Chr(colCnt2) & Chr(colCnt) Else colCnt = colCnt + 1 colNameMax = Chr(colCnt) End If Loop 'need to -1 from the column count to have accurate count If colCnt = 65 And colCnt2 = 65 Then colCnt = 90 colNameMax = Chr(colCnt) ElseIf colCnt = 65 And colCnt2 > 64 Then colCnt = 90 colCnt2 = colCnt2 - 1 colNameMax = Chr(colCnt2) & Chr(colCnt) ElseIf colCnt > 65 And colCnt < 91 And colCnt2 > 64 Then colCnt = colCnt - 1 colNameMax = Chr(colCnt2) & Chr(colCnt) Else colCnt = colCnt - 1 colNameMax = Chr(colCnt) End If
Well, just goes to show how much I have learned since finding this siteCode:lastCol = .Cells(14, .Columns.Count).End(xlToLeft).Column![]()
Last edited by Simi; 2012-05-17 at 09:56 PM.
You know, Simi, if the code you wrote the month before always makes you cringe it will mean you're always learning.![]()
Ken Puls, CMA, MS MVP (Excel)
Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter
If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.
Ken Puls, CMA, MS MVP (Excel)
Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter
If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.
Bookmarks