Questions tagged [vba]

Visual Basic for Applications; a subset of Visual Basic used in all Microsoft Office applications. Consider using this tag together with the tag for the specific application in question. Good questions on VBA generally contain some code and asks for solution of specific issues. Questions asking for entire solutions (please give me the code / how to do this and this with VBA) are off topic and will be closed as too broad.

Filter by
Sorted by
Tagged with
0 votes
2 answers
640 views

Merge Rows and Sum Single Value in Excel

I want to merge rows with mostly similar data but sum their quantity values, using the unique "id" value while keeping the rest of the data in the row intact. The raw output looks like this: ...
Catalog's user avatar
0 votes
1 answer
360 views

VBA code to auto hide rows based upon text in cell A1

I cannot seem to get my code for this sheet to work properly. I have code in there functioning fine which will hide rows based upon whether cells in a range are empty. However I would like to ...
Iain's user avatar
  • 1
0 votes
3 answers
535 views

Formatting cells to 000-000-0000-0000 in MS Excel

I would like to format cells in excel to the following format: 000-000-0000-0000. This is only an example and the zeros can be replaced with other numbers, but the hyphens need to stay. I think regex ...
enor's user avatar
  • 121
0 votes
1 answer
937 views

Excel VBA: How to use RegExp.replace to remove characters from a string?

In VBA Excel I am working with Regular Expressions. I have enabled Microsoft VBScript Regular Expressions 5.5 and am trying to use RegExp for the following. Input: "234;BB-154" Expected ...
OrigamiEye's user avatar
0 votes
0 answers
33 views

Turn link into URL when URL contains "="

I am using the following VBA function to turn a link into a URL Function GetURL(cell As Range) GetURL = cell.Hyperlinks(1).Address End Function I get #VALUE as a result I believe it is because ...
Steve Baker's user avatar
0 votes
1 answer
67 views

overflow error when to assign value in a cell

Assign value 300000 in the cell(1,1) : Sub test() ActiveSheet.Cells(1, 1) = 300000 End Sub Now replace 300000 with 500*600: Sub test() ActiveSheet.Cells(1, 1) = 500 * 600 End Sub Why it ...
newview's user avatar
  • 131
0 votes
0 answers
243 views

Excel VBA group by issue

ive been working on a group by function however ive run into an issue, because when the macro comes across a sheet with one row then it throws an exception at the commented line below when really it ...
Dan Ambrose's user avatar
2 votes
1 answer
105 views

VBA - Dynamic range skipping rows

For X = 9 To 36 For Y = 8 To 22 Step 14 If WS1.Cells(X, 1) = "TOT" Then X = X + 2 Buy= WorksheetFunction.SumIfs(Calls, Hour, WS1.Cells(X, 1), Data, WS1.Cells(Y, 2), Service, Number) + ...
Simone's user avatar
  • 21
0 votes
0 answers
604 views

How to copy and paste without overwriting in Excel using vba

I'm trying to paste a set of columns from one sheet to another. I want to paste the column WITHOUT deleting or overwriting on it. Can anyone suggest how to achieve this using vba. Sub copy_data() ...
hammed's user avatar
  • 1
2 votes
0 answers
206 views

Comparing one street address with a column of street addresses to find a match

I have two data sources with street address names, cities, and zips that I'm trying to find which addresses have the highest match percentages and return the maximum value. I have a VBA code that ...
Iyin's user avatar
  • 21
0 votes
2 answers
115 views

How can set integer in column as text instead of #####?

The value in column E is shown as below , all integer with Scientific way: I want to format it as text,all integer number shown as text format: With Worksheets("Sheet1").Range("E:E&...
newview's user avatar
  • 131
0 votes
2 answers
36 views

Why can't print the row number in sheet 'DataSet'?

I want to print the row number in sheet DataSet with vba: Sub cal() Dim x As Integer Worksheets("DataSet").Activate x = ActiveSheet.Range("A65535").End(xlUp).Row ...
newview's user avatar
  • 131
0 votes
1 answer
267 views

Hiding all rows whose visible cells are all empty but may have non-empty values in hidden cells

I'm trying to code a VBA macro that hides rows whose visible cells are all empty. This means, that rows whose visible cells are all empty but which also still have hidden cells with non-empty values ...
Madamadam's user avatar
  • 115
0 votes
1 answer
1k views

VBA variable and formula

Sub Test() Dim ABC As Integer ABC = [A1+(B2*C3)] 'Works fine Dim i as Long Dim XYZ As Integer For i = 1 to 100 XYZ = [A & i +(B & (i + 1) * C & (i + 2))] 'Not ...
Test_User's user avatar
0 votes
0 answers
183 views

How can I declare current page in vba macros word?

I want to know how to declare between current page, next page and a counter. I have this code: Dim docNew As Document With ActiveDocument Set Rng = .GoTo(What:=wdGoToNext) Rng.Collapse ...
Ulises Antonio Chávez's user avatar
0 votes
0 answers
27 views

Use Range on non adjacent Rows for graphs in subroutine

I am trying to set up several graphs with different non-adjacent rows for a line diagram (xlLineMarkers), but i cannot figure out how to hand over the defined ranges from a different sub. Code as ...
TrynRealHard's user avatar
1 vote
1 answer
110 views

Making the VBA code affect a specific range of pages

I have this very simple code Sub SortByTime() ' ' SortByTime Macro ' Sort by Time ' ' Keyboard Shortcut: Ctrl+Shift+M ' Range("C4:J43").Select ActiveWindow.SmallScroll Down:=-36 ...
Saher Naji's user avatar
0 votes
1 answer
321 views

How to put a Textbox on all word pages (No Header)?

I try to add a text box on each page to be able to modify in my own way (later) a book where it has "correct answers on that page (the pages will be on a specific page that I will not know until ...
Ulises Antonio Chávez's user avatar
0 votes
2 answers
2k views

Move data from multiple columns into one and remove duplicates

I currently have a situation wherein I require the unique data from multiple columns to be moved/identified in one single column. The data currently looks like this: Apple Microsoft Dell U.S U.S ...
Jack Miller's user avatar
0 votes
1 answer
214 views

Excel VBA find next cell if its empty add text

I have a worksheet with many buttons, If there is date in a field i want it to go to the next line, if there is not i need it to return a N/A or a 0.00. my code works if i just do this with one cell ...
John Hopper's user avatar
0 votes
0 answers
33 views

Macro that copy pastes a fix range into another sheet and takes into consideration a cell value

I'm pulling from Yahoo Finance the historical stock prices. You can only get with Power Query 100 lines. I have downloaded the history in one sheet and I have the Power Query with the last 100 days in ...
CuriousFox's user avatar
1 vote
0 answers
19 views

Excel 2019 Using VBA to colour sets of rows of cells w. two specific alternating colours, using unique value to identify which rows make a set [closed]

Colour rows of cells w. two alternating colours? Windows 10 Excel 2019 I have a spreadsheet that contains 31009 rows of data across 10 columns. The rows make up unique sets of data that belong ...
Kenny's user avatar
  • 77
0 votes
1 answer
130 views

Excel - list comments then hyperlink to original comments

I used the code listed in this post below including one extra line in comment within the same post to add the hyperlink. However, the hyperlink only works when the tab name has no space in it (i.e., ...
Nguyen's user avatar
  • 1
0 votes
1 answer
192 views

format date returns wrong result

I use an autofilter macro to get values from today - 3 months, but while the result seems to be correct, the formatted date is shown wrong: Sub LastThreeMonths() Dim strDateFirst As String ...
TrynRealHard's user avatar
0 votes
0 answers
188 views

Count dependents in other sheets VBA

I want to count the number of dependents of a cell in same sheet as well as in other sheets using VBA. I have used below code and results are in the picture. enter image description here Sub tst() Dim ...
User1991's user avatar
0 votes
1 answer
35 views

getting run time error when un-protecting the selected range

here i have getting run time error when i am un-protecting selected range by (UnProtectRange)-VBA and selected range is not unprotected i have used (ProtectRange)-VBA Macro to protect range by ...
visshnu's user avatar
0 votes
0 answers
55 views

How to Insert an autofilter if cell in row range contains value

I'm trying to create a function that inserts a filter within a cell range if a cell contains a value Here is my code: Sub FilterFunc() Dim i As Long, lastCol As Long Dim rng As Range, cell As ...
Dan Ambrose's user avatar
0 votes
1 answer
225 views

Excel - Transfer inputs from one sheet to another sheet to do calculations and returns a value

I'm just wondering if I could link the two sheets in Excel where you can transfer inputs from Sheet 1 to Sheet 2 to do some calculations and then return a value back to Sheet 1. See the attached ...
XDevil's user avatar
  • 1
0 votes
1 answer
288 views

Excel VBA: Flipping cells horizontally along with their formatting

I am trying to write a code which will flip my cells horizontally via Virtual Basic along with cells formatting (I need background colour to flip too). What I mean by flip is this: I came with the ...
Piotr Ciszewski's user avatar
0 votes
1 answer
406 views

Macro to create folder\subfolder\file.xlsm via Shell(cmd /c md)

I found this amazing code by nixda ... which creates a folder\subfolder structure named with values from a worksheet's cells. Creating folders and sub-folders with a VBA macro . Would it be possible ...
Bee Hoof's user avatar
0 votes
1 answer
2k views

MS Excel: generate a table with the number of rows depending on the input variables

So I want to make a matlab/r-like tool in excel that mimics more code driven calculations than the more common excel worksheet applications typically contain This workbook should contain: input sheet ...
babipsylon's user avatar
0 votes
1 answer
94 views

Range Definition for Autofilter in VBA Excel

I was wondering, what the correct way was to define a Range for an Autofilter. When recording a Macro it comes back with: Range("$A$4:$AS$600").AutoFilter Field:=1 Criteria1:= "Apples&...
TrynRealHard's user avatar
0 votes
0 answers
156 views

Excel freezes when running a macro which works on another sheet

when i run the below code on a sample document with a few columns, it works fine but as soon as i run it on a larger document excel just freezes SampleDoc Sample Doc code Sub RCOps_Compare() ...
Dando276's user avatar
0 votes
1 answer
47 views

Strange errors from Excel, when running VBA-macros

The macro stops before execution, points to a Trim(...) call (a VBA built-in function) and says: Extra tag: 'Can't find project or library'
Hannu's user avatar
  • 9,259
0 votes
0 answers
46 views

how to check via ExcelVBA if given file in directory has a change in the current month

I need to aggregate some values using from 2 to 3 different excel files via VBA. This works fine, but I want to implement a check if the available files in the directory are current (i.e. from the ...
TrynRealHard's user avatar
0 votes
1 answer
62 views

How to sort 3 unusual type of dates in Excel?

I have 3 types of dates in my excel files. These dates include the above : Q (quarter), Apr (Abbreviation or abbreviated name of the month), April (Full name of the month). These are combined with the ...
alex leiy's user avatar
0 votes
1 answer
816 views

Two computers show different numbers for same Excel document

I have two computers and when I open the same Excel on both of them, they display different numbers. It looks like this: First one shows number 135.05 while the other shows 135.059.003.051.757,00. ...
71GA's user avatar
  • 140
0 votes
1 answer
32 views

UDF / VBA Problems

I have been trying to use this line of code to bring out a currency however it also bring $[ at the front. Is there anyway I can stop this from happening? Dim s As String s = Replace(r....
Haz's user avatar
  • 1
0 votes
1 answer
184 views

How to change order of values in Excel?

I want to edit arrangement of values entered in a column and separated by a semicolon. For example this is a very small sample of my files: And now i want to convert to this: Note: Always the first ...
alex leiy's user avatar
0 votes
1 answer
251 views

How to get Excel Worksheet List Activate Toolbar?

I have many excel workbooks with many worksheets in them. It is always difficult to navigate between them. I found a VBA macro that shows the list of them using Macro. Here is the macro. Sub SheetMenu(...
DigitalNomad's user avatar
  • 1,688
0 votes
1 answer
308 views

Word VBA building blocks not immediately available at program start

I am using some shapes in a document, and recently switched from creating these on the fly (slow!) to using building blocks. I insert the blocks via VBA code, from a form. The building blocks are ...
MyICQ's user avatar
  • 242
1 vote
0 answers
98 views

How Can sort hundreds of emails in outlook alphabetically by company name?

So first of all, I have Windows 11 and my version of Microsoft Outlook is 2010. I am the accounts payable clerk for my company. I recently went paperless and am trying to find some shortcuts to ...
Jenny Young's user avatar
2 votes
1 answer
106 views

Trying to make CommandButton in Microsoft Word open a hyperlink

I have been having trouble trying to make a CommandButton object in my Word document redirect me to a website on click. I have tried using VBA code like this: Private Sub CommandButton2_Click() ...
Arnau Hanly's user avatar
0 votes
1 answer
946 views

Task Scheduler open Excel file with command line flag for VBA

I want to open a macro enabled workbook to capture data from the user every hour, and also pass an /e/ScheduledOpen flag to it to indicate in VBA if it was opened by task scheduler (in which case it ...
Greedo's user avatar
  • 767
0 votes
2 answers
204 views

Excel performance declining over time (hundreds of thousand + loop iterations/millions of calculations)

I am currently using a workbook where I connect to a MySQL database, download a recordset and then loop through 100,000s of unique IDs. The workbook has 31 sheets. Excel is ran in AWS where we open 5 ...
e_conomics's user avatar
0 votes
1 answer
40 views

How can I add vertical space before all instances of a particular style in Word?

In my Word document I'm trying to find a way to prefix any instances of the "Heading 2" (no matter what the actual text of the heading is) with a paragraph mark and 2 carriage returns. I'm ...
Nell's user avatar
  • 1
0 votes
1 answer
21 views

Creating a workbook based database-calculations-display system in Excel

I'm trying to make an Excel based modular reporting system so that each sections can be modified without messing up everyone else's reports. INPUT / Facts table: I have a database that is currently ...
Michael.C's user avatar
0 votes
1 answer
711 views

Excel: How do I list all the values in that column based on dynamic column header name?

This is my scenario, The "Creative Direction" Sheet is a template that I give to my clients. When it is returned to me, they've added extra columns in between of my columns. It takes a long ...
Ian M's user avatar
  • 1
0 votes
1 answer
119 views

How to make macro work with all cells of column A?

How to make macro work with all cells of column A? So that can paste into several cells at a time and the data is converted. I need this in order to be able to convert multiple data at once. I have ...
moninah's user avatar
  • 35
0 votes
1 answer
782 views

How fix macro error: "Runtime '9': Subscript out of range"?

If I enter or paste one word or one number, it gives an error: "Runtime '9': Subscript out of range". It is necessary that one character can be entered, but without conversion. If remove ...
moninah's user avatar
  • 35

1
3 4
5
6 7
75