• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Finding Labels of Columns

Hello,


If any cell contains comment(insert comment)than my output should be label of that respective column and value of fist cell of that raw. (All such comments are in sheet1)


I want this output in another sheet which content address of all cells having comment in sheet1.


Regards,

Pragnesh
 
Hi Pragnesh ,


The following code will display all cells which have a comment associated with them , by making use of the SpecialCells method.


If you are conversant with Excel VBA , you can get an idea of how to get what you want from this.


If you are not very conversant with VBA , please give full details of what you want :


1. Label of respective column : do you mean whether it is column A , B , C ... ?


2. Value of the first cell in the row


3. You want the output in another sheet , say Sheet2 ; you also say that this sheet contains the address of all cells which have comments in Sheet1. I am slightly confused by this.


Can you please copy + paste some sample data from both sheets ?


Narayan


Public Sub Get_Comment_Cells()

Application.ScreenUpdating = False

ThisWorkbook.Sheets("Sheet1").Range("A1:K10").SpecialCells(xlCellTypeComments).Activate

For Each cell In Selection

current_row = cell.Row

current_column = cell.Column

current_address = Chr(65 + current_column - 1) & Trim(Str(current_row))

MsgBox Range(current_address).Comment.Text

Next

Application.ScreenUpdating = True

End Sub
 
Hi Narayan,


Fist at all thanks for your valuable feedback.


Label of respective column is in Fist raw of sheet (ex. sheet2) contains various characteristic type of product such as BRAND1, BRAND2, BRAND OWNER INTERNATIONAL, WEIGHT, GROSS WEIGHT ETC....


My fist column in same sheet contains code of products,which is 10 digits like 8031321002

8031321007

8031320700

8031320707

8031320708

8031320711

8416085512


now if for particular products i have coded value for brand1=MARIDSUS which is wrong than my supervisor put comments(insert comment)by giving correct value in comment.


by using macro given below i get new sheet which has the value of cell(which i have originally coded) and value of that comments(which is given by supervisor)

also i get the cell address of cells which contains comment in sheet2 like... $CL$11, $Y$12......


but i also want PRODUCT CODED which is 10 digit number and also characteristic type for which supervisor has given comment.


I have following coded in module(Alt+F11)which i got from link www.contextures.com


Sub showcomments()

'posted by Dave Peterson 2003-05-16

Application.ScreenUpdating = False


Dim commrange As Range

Dim mycell As Range

Dim curwks As Worksheet

Dim newwks As Worksheet

Dim i As Long


Set curwks = ActiveSheet


On Error Resume Next

Set commrange = curwks.Cells _

.SpecialCells(xlCellTypeComments)

On Error GoTo 0


If commrange Is Nothing Then

MsgBox "no comments found"

Exit Sub

End If


Set newwks = Worksheets.Add


newwks.Range("A1:E1").Value = _

Array("Number", "Name", "Value", "Address", "Comment")


i = 1

For Each mycell In commrange

With newwks

i = i + 1

On Error Resume Next

.Cells(i, 1).Value = i - 1

.Cells(i, 2).Value = mycell.Name.Name

.Cells(i, 3).Value = mycell.Value

.Cells(i, 4).Value = mycell.Address

.Cells(i, 5).Value = Replace(mycell.Comment.Text, Chr(10), " ")

End With

Next mycell


newwks.Cells.WrapText = False

newwks.Columns.AutoFit


Application.ScreenUpdating = True


End Sub


could you help me to get output as PRODUCT CODED and CHAR. TYPE for respective cells along with value of cell and value of comment?


Thanks,

Pragnesh
 
Hi Pragnesh ,


Thanks for the detailed post. I am still somewhat confused , so let me put this in my own words.


1. Sheet2 has the following column labels in row 1 : BRAND1, BRAND2, BRAND OWNER INTERNATIONAL, WEIGHT, GROSS WEIGHT ETC.... Thus cell B1 has "BRAND1" , cell C1 has "BRAND2" ,....


2. Column A in this worksheet has the following column label in A1 : PRODUCT CODE


3. Product codes are 10 digit codes , based on which you will enter the corresponding Brand Name in column B ( cells B2 onwards ).


4. If the entered brand name is wrong , the correct brand name will be entered in the form of a comment ; I assume this will be in the same cells as the entered brand names ( cells B2 onwards ).


5. It is also possible that similar wrong values might be entered in any of the other columns , under BRAND2, BRAND OWNER INTERNATIONAL, WEIGHT, GROSS WEIGHT ETC.... ; in such a case , the correct value will be entered as a comment against the respective cell.


6. You would like to scan this worksheet for each comment , and put the following , in a separate area in Sheet1 :


a) The Product Code corresponding to which the comment was made

b) The column label ( whether the correction was for BRAND1 , BRAND2 ,... ) where the correction was made

c) The correct entry , as mentioned in the comment


Is this correct ?


Narayan
 
Hi Narayan,


Thanks again for Quick response.


yes i want exactly what you have mentions.


a) The Product Code corresponding to which the comment was made

b) The column label ( whether the correction was for BRAND1 , BRAND2 ,... ) where the correction was made

c) The correct entry , as mentioned in the comment

and

d)also the wrong value entered by me.


Regards,

Pragnesh
 
Hi Pragnesh ,


Try this code out and see.


Public Sub Get_Comment_Cells()

Application.ScreenUpdating = False

Entry_Count = 1

Start_Range = "A1" ' Change this to whatever is correct.

End_Range = "F8" ' Change this to whatever is correct.

Raw_Data_Sheet = "Sheet2"

Report_Sheet = "Sheet3"

ThisWorkbook.Sheets(Raw_Data_Sheet).Select

Range(Start_Range, End_Range).SpecialCells(xlCellTypeComments).Activate

Comment_Author = ActiveCell.Comment.Author

Extra_Length = Len(Comment_Author) + 1

For Each cell In Selection

current_row = cell.Row

current_column = cell.Column

current_address = Chr(65 + current_column - 1) & Trim(str(current_row))

Product_code = Range(current_address).Offset(0, -current_column + 1).Value

Column_Label = Range(current_address).Offset(-current_row + 1, 0).Text

Comment_Full = Range(current_address).Comment.Text

Correct_Entry = Right(Comment_Full, Len(Comment_Full) - Extra_Length)

Wrong_Value = Range(current_address).Value

ThisWorkbook.Sheets(Report_Sheet).Activate

Range(Start_Range).Offset(Entry_Count, 0).Value = Product_code

Range(Start_Range).Offset(Entry_Count, 1).Value = Column_Label

Range(Start_Range).Offset(Entry_Count, 2).Value = Wrong_Value

Range(Start_Range).Offset(Entry_Count, 3).Value = Correct_Entry

Entry_Count = Entry_Count + 1

Sheets(Raw_Data_Sheet).Activate

Next

Application.ScreenUpdating = True

End Sub


Narayan
 
Hi Narayan,


I i am getting error as followes: "Run-time error '1004': No cells were found."


In module follwing line is highlited in yellow back ground when i click Debuge option.


Range(Start_Range, End_Range).SpecialCells(xlCellTypeComments).Activate


Thanks,

Pragnesh
 
Hi Pragnesh ,


From your description , it appears that there are no cells with comments ; is this so ?


The error itself can be disabled by the following statement at the beginning of the procedure :


On Error Resume Next


But , first , please check whether any cells having comments are present in your worksheet.


Narayan
 
Hi Narayan,


This time error code is 9. Subscript out of rang.


If i put "On Error Resume Next" just before about line and try to run macro again than i get Run time error '438': object doesn't support this property or method.


and line "Wrong_Value = Range(current_address).Value3" in yellow background.


Some times file got hanges.


Regards
 
Hi Narayan,


I have readymade macro having three macro buttons.


Button1 Number Commets-- which give number to cell comments like 1,2,3,...etc

Button2 clear Number-- which is used to remove number given to cell comments.

Button3 List Comments--gives output in new sheet having columns like Sr.No, Name, Current Value of cell, Address of cell having comment, and Commnet value.


But I need additional two colums. viz.,

a) The Product Code corresponding to which the comment was made

b) The column label ( whether the correction was for BRAND1 , BRAND2 ,... ) where the correction was made.


which contains following code


Option Explicit

' Developed by Contextures Inc.

' www.contextures.com

Sub RemoveIndicatorShapes()


Dim ws As Worksheet

Dim shp As Shape


Set ws = ActiveSheet


For Each shp In ws.Shapes

If Left(shp.Name, 6) = "CmtNum" Then

shp.Delete

End If

Next shp


End Sub


Sub CoverCommentIndicator()

Dim ws As Worksheet

Dim cmt As Comment

Dim lCmt As Long

Dim rngCmt As Range

Dim shpCmt As Shape

Dim shpW As Double 'shape width

Dim shpH As Double 'shape height


Set ws = ActiveSheet

shpW = 8

shpH = 6

lCmt = 1


'clear any existing numbers

RemoveIndicatorShapes


For Each cmt In ws.Comments

Set rngCmt = cmt.Parent

With rngCmt

Set shpCmt = ws.Shapes.AddShape(msoShapeRectangle, _

rngCmt.Offset(0, 1).Left - shpW, .Top, shpW, shpH)

End With

With shpCmt

.Name = "CmtNum" & .Name

With .Fill

.ForeColor.SchemeColor = 9 'white

.Visible = msoTrue

.Solid

End With

With .Line

.Visible = msoTrue

.ForeColor.SchemeColor = 64 'automatic

.Weight = 0.25

End With

With .TextFrame

.Characters.Text = lCmt

.Characters.Font.Size = 6

.Characters.Font.ColorIndex = xlAutomatic

.MarginLeft = 0#

.MarginRight = 0#

.MarginTop = 0#

.MarginBottom = 0#

.HorizontalAlignment = xlCenter

End With

.Top = rngCmt.Top + 0.001

End With

lCmt = lCmt + 1

Next cmt


End Sub


Sub showcomments()

'posted by Dave Peterson 2003-05-16

Application.ScreenUpdating = False


Dim commrange As Range

Dim mycell As Range

Dim curwks As Worksheet

Dim newwks As Worksheet

Dim i As Long


Set curwks = ActiveSheet


On Error Resume Next

Set commrange = curwks.Cells _

.SpecialCells(xlCellTypeComments)

On Error GoTo 0


If commrange Is Nothing Then

MsgBox "no comments found"

Exit Sub

End If


Set newwks = Worksheets.Add


newwks.Range("A1:E1").Value = _

Array("Number", "Name", "Value", "Address", "Comment")


i = 1

For Each mycell In commrange

With newwks

i = i + 1

On Error Resume Next

.Cells(i, 1).Value = i - 1

.Cells(i, 2).Value = mycell.Name.Name

.Cells(i, 3).Value = mycell.Value

.Cells(i, 4).Value = mycell.Address

.Cells(i, 5).Value = Replace(mycell.Comment.Text, Chr(10), " ")

End With

Next mycell


newwks.Cells.WrapText = False

newwks.Columns.AutoFit


Application.ScreenUpdating = True


End Sub


Is it possible to update the above makro as per my need? ....or we need to have new macro.


Regards,

Pragnesh
 
Hi Pragnesh ,


Insert the following code between the two lines which are already in your code :


.Cells(i, 5).Value = Replace(mycell.Comment.Text, Chr(10), " ") 'line already exists

'///////////////////////////////////////////////

'/

'/

'/

current_row = mycell.Row

current_column = mycell.Column

.Cells(i, 6).Value = mycell.Offset(0, -current_column + 1).Value

.Cells(i, 7).Value = mycell.Offset(-current_row + 1, 0).Text

'/

'/

'/

'///////////////////////////////////////////////

End With 'line already exists


Narayan
 
Hi Narayan,


I am unable to judge where to add above coded ....as i not regular user of codes...


Is it possible for you to give me whole new code.


Regards,

Pragnesh
 
Hi Pragnesh ,


Replace the ShowComments procedure with this modified one :


Sub showcomments()

'posted by Dave Peterson 2003-05-16

Application.ScreenUpdating = False


Dim commrange As Range

Dim mycell As Range

Dim curwks As Worksheet

Dim newwks As Worksheet

Dim i As Long


Set curwks = ActiveSheet


On Error Resume Next

Set commrange = curwks.Cells.SpecialCells(xlCellTypeComments)

On Error GoTo 0


If commrange Is Nothing Then

MsgBox "no comments found"

Exit Sub

End If


Set newwks = Worksheets("Sheet3")


newwks.Range("A1:E1").Value = Array("Number", "Name", "Value", "Address", "Comment")


i = 1

For Each mycell In commrange

With newwks

i = i + 1

On Error Resume Next

.Cells(i, 1).Value = i - 1

.Cells(i, 2).Value = mycell.Name.Name

.Cells(i, 3).Value = mycell.Value

.Cells(i, 4).Value = mycell.Address

.Cells(i, 5).Value = Replace(mycell.Comment.Text, Chr(10), " ")

'///////////////////////////////////////////////

'/

'/

'/

current_row = mycell.Row

current_column = mycell.Column

.Cells(i, 6).Value = mycell.Offset(0, -current_column + 1).Value

.Cells(i, 7).Value = mycell.Offset(-current_row + 1, 0).Text

'/

'/

'/

'///////////////////////////////////////////////

End With

Next mycell


newwks.Cells.WrapText = False

newwks.Columns.AutoFit


Application.ScreenUpdating = True


End Sub


Narayan
 
Hi Pragnesh ,


Are you copying and pasting the code which has been given here ?


I have run this same code on my PC and I am not getting any error.


Narayan
 
Hi Narayan,


could you send me excel file with ready code to my mail address: pragnesh_50@yahoo.in


Because i am uanable to run macro successfully as it gives error viz., vriable are not define.


Regards,

Pragnesh
 
Hi Narayan,


Thanks for your mail


I have downloaded yr file and try to run macro it the same but still facing problems.


I have replied your mail with error print shoot.


Regards,

Pragnesh
 
Hi Narayan,


Thanks for your Kind reply on email. My problem is really resolved.


Now i am able to get Product code and Char. types.


Thanks Narayan....Thanks....Chandoo.org


Regards,

Pragnesh
 
Hi Narayan,


When i try to past lines containing comments form file created by my supervisor to our macro file i only able to past Lines only and comments are not pasted.


Regards,

Pragnesh
 
Hi Pragnesh ,


I am not able to understand your problem. Can you say how this process is done ?


What is the comments form file created by your supervisor ? How are you transferring data from that file into your file ?


Narayan
 
HI Narayan,


Every Friday our validator generate report form our inbuilt system in CSV and convert it in excel file.


He do his validated in normal excel files having comments on shared drive which can be accessed by Indian group as well as other country group.


We are just taking that file on over local drive and all such lines having comment are copied and pasted to this macro enable file (which is given by you).


But while pasting that items from to our file i am getting only lines and not comments(cell comment).


Hope you got it.


Regards,

Pragnesh
 
Hi Pragnesh ,


How are you copying and pasting the lines ?


If you are doing it using Excel , then if you use a Copy + Paste , the comments should also get copied.


If you are using Paste Special , Values , then do another Paste Special , Comments.


Narayan
 
Hi Narayan,


I have send you mail with valditor file.


and next mail with Pragneshmacro file.


Kinldy look in to the matter.


Regards,

Pragnesh
 
Back
Top