Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10
Default Keep getting error, wont run macro! HELP!

Okay so using some code i have tried and tried to get this to work in
different ways but cant figure out why it's not working


For easy sakes we will say that

intRowNum = 2
strDescription = "Comment goes here"

' This should basically have theCell return as like "D2" or whichever letter
it is

theCell = ColumnLetter(LastColumn(intRowNum)) & intRowNum
Range(theCell).AddComment (strDescription)



Function LastColumn(Row As String) As String
' This gets the last column in a row when the row is specified
LastColumn = ActiveSheet.Cells(intRowNum,
Columns.Count).End(xlToLeft).Column + 1
End Function


Function ColumnLetter(ColumnNumber As Integer) As String
' This converts the column back to the appropriate letter
If ColumnNumber 26 Then
ColumnLetter = Chr(Int((ColumnNumber - 1) / 26) + 64) & _
Chr(((ColumnNumber - 1) Mod 26) + 65)
Else
ColumnLetter = Chr(ColumnNumber + 64)
End If
End Function



Basically i already know what the row is, i just need to find the last
column of that row that has no text in it, and then add my own comment to it.

Thanks for the help guys!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Keep getting error, wont run macro! HELP!

You can use cells() instead of Range() and it'll make life easier:

cells(intrownum,"D").addcomment strdescription
or
cells(intrownum,4).addcomment strdescription

So

Dim LastCol as long
with activesheet
lastcol = .cells(intrownumb,.columns.count).end(xltoleft).co lumn
.cells(intrownum,lastcol).addcomment strdescription
'or for one cell to the right of that last column
.cells(intrownum,lastcol+1).addcomment strdescription
end with







Myles wrote:

Okay so using some code i have tried and tried to get this to work in
different ways but cant figure out why it's not working

For easy sakes we will say that

intRowNum = 2
strDescription = "Comment goes here"

' This should basically have theCell return as like "D2" or whichever letter
it is

theCell = ColumnLetter(LastColumn(intRowNum)) & intRowNum
Range(theCell).AddComment (strDescription)

Function LastColumn(Row As String) As String
' This gets the last column in a row when the row is specified
LastColumn = ActiveSheet.Cells(intRowNum,
Columns.Count).End(xlToLeft).Column + 1
End Function

Function ColumnLetter(ColumnNumber As Integer) As String
' This converts the column back to the appropriate letter
If ColumnNumber 26 Then
ColumnLetter = Chr(Int((ColumnNumber - 1) / 26) + 64) & _
Chr(((ColumnNumber - 1) Mod 26) + 65)
Else
ColumnLetter = Chr(ColumnNumber + 64)
End If
End Function

Basically i already know what the row is, i just need to find the last
column of that row that has no text in it, and then add my own comment to it.

Thanks for the help guys!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,533
Default Keep getting error, wont run macro! HELP!

Hi

This should do it

Sub test()
Dim intRowNum As Integer
intRowNum = 2
strDescription = "Comment goes here"

LastColumn = ActiveSheet.Cells(intRowNum,
Columns.Count).End(xlToLeft).Column + 1
' This should basically have theCell return as like "D2" or whichever letter
it is

theCell = Cells(intRowNum, LastColumn).Address
Range(theCell).AddComment (strDescription)
'or
' cells(intRowNum, LastColumn).AddComment(strDescription)
End Sub

Regards,
Per

"Myles" skrev i meddelelsen
...
Okay so using some code i have tried and tried to get this to work in
different ways but cant figure out why it's not working


For easy sakes we will say that

intRowNum = 2
strDescription = "Comment goes here"

' This should basically have theCell return as like "D2" or whichever
letter
it is

theCell = ColumnLetter(LastColumn(intRowNum)) & intRowNum
Range(theCell).AddComment (strDescription)



Function LastColumn(Row As String) As String
' This gets the last column in a row when the row is specified
LastColumn = ActiveSheet.Cells(intRowNum,
Columns.Count).End(xlToLeft).Column + 1
End Function


Function ColumnLetter(ColumnNumber As Integer) As String
' This converts the column back to the appropriate letter
If ColumnNumber 26 Then
ColumnLetter = Chr(Int((ColumnNumber - 1) / 26) + 64) & _
Chr(((ColumnNumber - 1) Mod 26) + 65)
Else
ColumnLetter = Chr(ColumnNumber + 64)
End If
End Function



Basically i already know what the row is, i just need to find the last
column of that row that has no text in it, and then add my own comment to
it.

Thanks for the help guys!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't figure out why Macro wont work???? Krefty Excel Worksheet Functions 0 November 2nd 07 12:06 AM
2007 Upgrade wont run macro BrianW Excel Discussion (Misc queries) 0 June 26th 07 04:44 AM
Date format from excel to CVS file wont. Change in CVS wont stay. Fish''s Mermaid Excel Worksheet Functions 1 October 14th 06 12:28 AM
Macro wont run! Joe Excel Discussion (Misc queries) 9 January 17th 06 07:01 PM
Macro that wont go away - Help taxmom Excel Worksheet Functions 3 April 13th 05 06:39 PM


All times are GMT +1. The time now is 04:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"