• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

string as replace for column|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / string as replace for column|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & Macrosstring as replace for column
sp_PrintTopic sp_TopicIcon
string as replace for column
Avatar
Trias

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
September 9, 2022
sp_UserOfflineSmall Offline
1
September 9, 2022 - 3:16 pm
sp_Permalink sp_Print

Hi all,

My problem is, that my code is too long, as I wanted to crate some calculates in the comments.
I need to have 4044 cells with a calculated comment

to do that I used the following:
Range("N5").Comment.Text Text:=[AV5].Text

But If I use more that 450 commands, then VBA tell me, that the code is too big.
is it possible to make a variable or string for a column?
My table has a dimension of 337x12 cells (for each month 337 cells)
to short this codes, I can use more makros for each month; eg January f�r column "N" and "AV" etc.

what I like to have should look like:

Sub Makro1()
Range(y"5").Comment.Text Text:=[z"5"].Text
Range(y"6").Comment.Text Text:=[z"6"].Text
...
end sub

Sub Makro2()
dim y as string
dim z as string
y = N
z = AV
call Makro1()
end sub

 

thank you for your help

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
September 9, 2022 - 8:02 pm
sp_Permalink sp_Print

Hi Trias,

You can use this:

Sub Makro2()
dim y as string
dim z as string
y = "N"
z = "AV"
Makro1 y, z ' call and pass variables
end sub

Sub Makro1(ByVal y as string, ByVal z as string)
Range(y & "5").Comment.Text Text:=Range(z & "5").Text
Range(y & "6").Comment.Text Text:=Range(z & "6").Text
...
end sub

 

Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 616
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
3
September 12, 2022 - 6:39 pm
sp_Permalink sp_Print sp_EditHistory

If your rows are all next to each other (or even just evenly spaced out) you could also add a loop to makro1:

 

Sub Makro1(ByVal y as string, ByVal z as string)

Dim n as long

for n = 1 to 337
Cells(n + 4, y).Comment.Text Text:=Cells(n + 4, z).Text
Next n
end sub

Avatar
Trias

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
September 9, 2022
sp_UserOfflineSmall Offline
4
September 14, 2022 - 3:47 pm
sp_Permalink sp_Print sp_EditHistory

Thank you all

I changed the code as follow:

Sub Makro1()

Dim kom As Comment
Dim n As Integer
Dim Cell As Object

Selection.SpecialCells(xlCellTypeComments).Select

Selection.ClearComments

Range("M3").Select

n = 1
Do While n < 338

On Error Resume Next
For Each Cell In Selection

If Cell.Value > -1 Then
Set kom = Cell.AddComment
kom.Text Chr(10) & ActiveCell.Rows.Offset(0, 34).Value
End If
Next Cell
ActiveCell.Offset(1, 0).Select
n = n + 1
Loop

End Sub

 

works fine as I needed - thank you for your inspiration.

 

with the "if cell > -1 then" code, I can jump over the "not needed" cells, as long as I typed in invisible -1 and block the cell for editing.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Philip Treacy, Jack Brett, Natasha Smith
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
LAFONSO HERNANDEZ
Hayden Hao
Angela chen
Sean Moore
John Chisholm
vexokeb sdfg
John Jack
Malcolm Toy
Ray-Yu Yang
George Shihadeh
Forum Stats:
Groups: 3
Forums: 24
Topics: 6211
Posts: 27239

 

Member Stats:
Guest Posters: 49
Members: 31891
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.