VBA Help - Insert columns if there are any comments

kreepa

Board Regular
Joined
Mar 24, 2005
Messages
57
I hope this is an easy one.

I want to insert an adjacent column IF there are any comments in a column.

I would like to then use the following code to insert the comments into the empty fields:

Sub ShowCommentsNextCell()
Application.ScreenUpdating = False

Dim commrange As Range
Dim mycell As Range
Dim curwks As Worksheet

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

For Each mycell In commrange
If mycell.Offset(0, 1).Value = "" Then
mycell.Offset(0, 1).Value = mycell.Comment.Text
End If
Next mycell

Application.ScreenUpdating = True

End Sub

Can this code be modified to run through all sheets?

I then run a merge macro to combine ll the sheets.

My head hurts.

Thanks
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Yes, kreepa, it should be easy enough. However, I think it will be easier instead of checking a whole worksheet to work one column at a time through each worksheet. You will also have to consider how many columns you want to add - due to the column limit of 256. That is, if you have 200 columns and want to add 100 more it won't work. Another tip, it might be easiest to work from the rightmost column to the left as you loop through the columns on the worksheet - it is simpler this way as you add columns on the fly.

Regards,
Fazza
 
Upvote 0
I see your point. I would like to go row by row and only insert a column IF there are any comments in the querried column.

For Example --> If there areno comments in A1 but there is a comment in A2 the macro would insert a blank column B.

Additionally, if every row in column A had a comment the macro would insert a blank column B, NOT a hundred empty columns.
 
Upvote 0
kreepa,

I understand your requirement; you initially described it quite well.

Column by column is a simpler way to go, not row by row. You can check if the rightmost column has comments, if so add a column and then one by one the comments. Work through the columns heading left.

If you go row by row, you have an extra step to code - to know if there is already a column added. It just adds unnecessary complexity.

KISS,
Fazza
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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