Copy “Comments” using VBA, with a twist.

julhs

Active Member
Joined
Dec 3, 2018
Messages
471
Office Version
  1. 2010
Platform
  1. Windows
Have a large “Input Section” (16 Cols & 500-700 Rows) that has comments scattered throughout it, currently my “Analysis Section” only contains values taken from the “Input Section” using {=IF(SUMPRODUCT,ROWS,INDEX,SMALL………)}

My understanding is that I can’t use a formula to get the “Comments” from the “Input Section” into the corresponding cell in the “Analysis Section”.

What I want to do is get the Values & Comments into the Analysis Section, presently I have to copy/paste "Comments" individually.

Is there a way to do this retrospect fully with VBA from a Command button?
P.S "Comments" dont seem to be appearing on XL2BB, cells with "Fill colour" are ones with Comments
Accounts 2016 - 2019 Final Currant.xlsm
ABCDEFGHIJKLMN
1
2CASH BOOK
3DEBITS
4DateInvoice #Payment Method ListPayment Details ListBank & CashRentPowerMotoring Expenses Stock & MaterialsOffice
5
6Jul-05gs0370Direct DebitRent250.00250.00INPUT SECTION All details etc on left are Enterd via a USERFORM, including the comments. It finds the next empty Row & pastes in Userform values, then inserts a new blank row and formats it
7Jul-10gs0375Direct DebitEDF35.0035.00
8Jul-15gs0380Debit CardMicks Garage50.0050.00
9Jul-20gs0385Debit CardHalfords20.0020.00
10Jan-21gs0390Debit CardSouthern Building Supplies31.0031.00
11Jul-22gs0415Debit CardAmazon42.0042.00
12Jul-24gs0433PayPalDirect Stationary Supplies10.0010.00
13Aug-05gs0450Direct DebitRent275.00275.00
14Aug-10gs0460Debit CardWessex Steel40.0040.00
15Aug-10gs0462Direct DebitEDF50.0050.00
16
17Totals803.00525.0085.0070.0071.0052.00
18
19
20ANALYSIS SECTION RentEDFMicks GarageHalfordsSouthern Building SuppliesWessex SteelDirect Stationary SuppliesAmazon
21This section lists all the entries for individual supplier using SUMPRODUCT,ROWS,INDEX,SMALL. It does get bumped down as rows are added above250.0035.0050.0020.0031.0040.0010.0042.00
22275.0050.00      
23
24
25This is what I would like the desired outcome to beRentEDFMicks GarageHalfordsSouthern Building SuppliesWessex SteelDirect Stationary SuppliesAmazon
26250.0035.0050.0020.0031.0040.0010.0042.00
27275.0050.00
Testing (2)
Cell Formulas
RangeFormula
F17:K17F17=SUM(F6:F15)
G21:N22G21=IF(SUMPRODUCT(--($E$5:$E$15=G$20))>=ROWS(G$21:G21),INDEX($F$5:$F$15,SMALL(IF($E$5:$E$15=G$20,ROW($E$5:$E$15)-ROW($E$5)+1),ROWS(G$21:G21))),"")
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Q: what does "retrieve" mean? Copy to Q or move to Q? Or something else?
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
wish we had more than 10 minutes to edit a post.
Another question: OK to copy everything from E (such as interior colour) or would just values be a priority?
 
Upvote 0
My “Minimum” being “Optiom 1” ; ALL the Comments/Notes from Col F into Col Q.
The BEST option is option 2, “Next Best” ; values from Col E into Col P and also/then retrieve from Col F ”Comments & values” into Col Q
 
Upvote 0
My “Minimum” being “Optiom 1” ; ALL the Comments/Notes from Col F into Col Q.
The BEST option is option 2, “Next Best” ; values from Col E into Col P and also/then retrieve from Col F ”Comments & values” into Col Q

Same issue as you with editing time!!
My “Minimum” being “Optimum 1” : ALL the Comments/Notes from Col e into Col Q.

The BEST option is “Next Best”, values from Col E into Col P and also/then retrieve from Col F ”Comments & values” into Col Q .
My “Minimum” is “Optiom 1” : ALL the Comments/Notes from Col E into Col Q.

The BEST option is option 2 (“Next Best”); values from Col D into Col P and also/retrieve from Col E ”Comments/Notes & values” into Col Q

"retrieve" means everything, 'Values and Comments/Notes' from E to Q.

Just had a vague thought that "Comments/Notes" are classed as 'Formatting'??

This post is bcoming a right royal pain in the a****, glichie mouse and intermitant internat!!!

Will leave it with you.
Juhls
 
Upvote 0
This is is hopless!!!
Any edit i make is just useless!!
To a degree; be vary of Col ref's that I have posted to date!

I will double check things in the morning, hoping for better Internet connection
 
Upvote 0
Posting a revised Xl2bb in the hope that;
a) It is simplified
b) Reflects the change of direction we need to take from my initial post #1

So essentially what we are NOW looking to do is compile a list by:-
1) Look in Col F for cells with “Comments/Notes”
(I’m using Excel 2010, so the old “Comments”, xl2b didn’t transfer them so resorted to using luminous green fill colour to indicate cells that are supposed to contain “Comments”)
2) IF there is a “Comment” in any cell in Col F; the corresponding Details + Formatting in Col E, the Value + Formatting + ”Comment” in Col F are copied over to Col P & Q respectfully

That will give me a list in Col P & Q to work from; I could then potentially apply a filter to it !!??

I have yet to decide as to whether to run the code via a command button on demand, or incorporate it into the Sheets main code. My thinking is the former as I won’t utilise the data in Col P & Q until ALL entries have been made in the INPUT SECTION (upwards of 700 rows)
Accounts 2016 - 2019 Final Currant.xlsm
BCDEFGHIJKLMNOPQ
3DEBITS
4DateInvoice #Payment Method ListPayment Details ListBank & CashRentPowerMotoring Expenses Stock & MaterialsOffice
5
6Jul-05gs0370Direct DebitRent250.00250.00INPUT SECTION All details etc on left are Enterd via a USERFORM, including the comments. It finds the next empty Row & pastes in Userform values, then inserts a new blank row and formats itMicks Garage50.00
7Jul-10gs0375Direct DebitEDF35.0035.00Halfords20.00
8Jul-15gs0380Debit CardMicks Garage50.0050.00Rent275.00
9Jul-20gs0385Debit CardHalfords20.0020.00EDF50.00
10Jan-21gs0390Debit CardSouthern Building Supplies31.0031.00
11Jul-22gs0415Debit CardAmazon42.0042.00
12Jul-24gs0433PayPalDirect Stationary Supplies10.0010.00
13Aug-05gs0450Direct DebitRent275.00275.00
14Aug-10gs0460Debit CardWessex Steel40.0040.00
15Aug-10gs0462Direct DebitEDF50.0050.00
16
Testing (3)
 
Upvote 0
Based on your posted data sample.
This should find the last row with a comment in column F then loop from row 6 to that point and copy those comments as well as data from F
and E columns for those rows. Then it should paste the data and comments into P and Q columns beginning at row 6. Hopefully, it is compatible with the older versions of Excel where what you want was characterized as "comments". Change your sheet name accordingly.

I don't know how you actually intend to use this so it may need some tweaking. F'rinstance, perhaps PQ should be cleared because if you run this and there are 6 notes copied, then run again and there are only 5, you'll likely end up with 6 because one will remain from a prior operation. In that case, add this bold line at this location:

Set sht = ThisWorkbook.Sheets("005")
sht.Range("P:Q").Clear

VBA Code:
Sub juhls2()
Dim Lrow As Long, DestRow As Long, i As Integer
Dim rng As Range
Dim sht As Worksheet

Set sht = ThisWorkbook.Sheets("005")
Lrow = sht.Cells(Rows.count, "F").End(xlUp).Row
DestRow = 6

For i = 6 To Lrow
     Set rng = Range("F" & i)
     If Not rng.Comment Is Nothing Then
         sht.Range("E" & i & ":F" & i).Copy
         sht.Range("P" & DestRow & ":Q" & DestRow).PasteSpecial xlPasteAll
         DestRow = DestRow + 1
     End If
Next

Application.CutCopyMode = False
sht.Range("P" & DestRow + 1).Offset(1, 0).Select

End Sub
 
Upvote 0
Revised to clear PQ range and restrict copying of comments to the row containing the Totals.
VBA Code:
Sub juhls2()
Dim Lrow As Long, DestRow As Long, i As Integer
Dim rng As Range
Dim sht As Worksheet

Set sht = ThisWorkbook.Sheets("005")
sht.Range("P:Q").Clear

Set rng = sht.Range("D:D").Find(What:="Totals", LookIn:=xlValues, LookAt:=xlWhole)
Lrow = rng.Row
DestRow = 6

For i = 6 To Lrow
     Set rng = Range("F" & i)
     If Not rng.Comment Is Nothing Then
          sht.Range("E" & i & ":F" & i).Copy
          sht.Range("P" & DestRow & ":Q" & DestRow).PasteSpecial xlPasteAll
          DestRow = DestRow + 1
     End If
Next

Application.CutCopyMode = False
sht.Range("P" & DestRow + 1).Offset(1, 0).Select

End Sub
 
Upvote 0
Solution
Micron, many thanks!!!!!!!

That entirely deals with the required change in tack that was required; it gets the results that I can use to get to my ultimate goal.
Your help is GREATLY appreciated!!!!

For those that read this later:
This is a work around to the inability of formulas and vLookup to return anything other than values, also to a limited extent the filter function. (Yes a filter function will return the comments but only for the single filter criteria, so you need to keep re-filtering).
This will return a complete contiguous list (to Col P & Q ) of All cells in Col F that contain a “Comment” (as they appeared in the source cell), along with the corresponding values of Col E.
The line;
Excel Formula:
Set rng = sht.Range("D:D").Find(What:="Totals", LookIn:=xlValues, LookAt:=xlWhole)
is a range limiter for the search. By doing it this way, it doesn’t matter how many rows there are between Row 6 and the “Totals” row (so you can insert as many rows as you like between row 6 & “Totals” row, but still get a complete list regardless of how many rows there are.

I’m more than expecting to get corrected/shot down on my statements but I am prepared to make then.
 
Upvote 0
Hope it continues to work for a long time!
You're welcome.
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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