Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all 50222 articles
Browse latest View live

Error with a formula in my macro that is not allowing my macro to run

$
0
0
Hi

I tried to amend the following macro however before I can proceed any further its giving me an error

The first line of formula works ok

The second and third lines of formula is where the problem lies

will appreciate all help in order to fix my macro wherever possible

Thank you in anticipatioe

Code:

Sub MacroTest()
   
'Sheets("Analysis").UsedRange.Offset(1).Clear'
Application.DisplayAlerts = False
On Error Resume Next
Worksheets("RaceData").Delete
On Error GoTo 0
Application.DisplayAlerts = True
   
Worksheets("Racescrape").Copy Before:=Worksheets(1)

With Worksheets(1)

.Name = "Racedata"
 
LR = .Cells(Rows.Count, 1).End(xlUp).Row

Columns("K:K").EntireColumn.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("o:o").EntireColumn.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("K:K").EntireColumn.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

On Error Resume Next
SR = .Columns(1).Find("Tab", LookIn:=xlValues, Lookat:=xlPart).Row
On Error GoTo 0

If IsError(Z) Then GoTo Quit:

FindLoop:

LR = .Cells(Rows.Count, 1).End(xlUp).Row

If SR > LR Then GoTo Quit

On Error Resume Next
ER = 0
ER = .Range("A" & SR + 1 & ":A" & LR).Find("Tab", LookIn:=xlValues, Lookat:=xlPart).Row
On Error GoTo 0

If ER = 0 Then GoTo Quit

V = ER - SR

If V <> 27 Then


If V < 27 Then
    .Rows(ER - 5 & ":" & ER + 21 - V).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
   
 Else
    .Rows(SR + 23 & ":" & ER - 5).EntireRow.Delete

End If
End If

Range("K" & SR + 1 & ":K" & SR + 22).FormulaR1C1 = "=IF(RC[-1]="""","""",(RC[-2]+RC[-1])/2)"
Range("K" & SR + 1 & ":K" & SR + 22).Value = Range("K" & SR + 1 & ":K" & SR + 22).Value

Range("0" & SR + 1 & ":0" & SR + 22).FormulaR1C1 = "=SUM(--MID(SUBSTITUTE("-"&N6,"-",REPT(" ",15)),{15;30},15))/2)"
Range("0" & SR + 1 & ":0" & SR + 22).Value = Range("0" & SR + 1 & ":0" & SR + 22).Value

Range("q" & SR + 1 & ":q" & SR + 22).FormulaR1C1 = "=SUM(--MID(SUBSTITUTE("-"&p6,"-",REPT(" ",15)),{15;30},15))/2)"
Range("q" & SR + 1 & ":q" & SR + 22).Value = Range("q" & SR + 1 & ":q" & SR + 22).Value


SR = SR + 27
 
GoTo FindLoop

Quit:
  .Range("A:br").EntireColumn.AutoFit
End With

End Sub

Attached Files

make a button that will sort and send data to another sheet

$
0
0
Hi all,
This question is also posted in reddit
Thanks in advance. I have the below spreadsheets. I enter data into the input sheet and it moves to the data sheet and then clears the input sheet ready for the next data (that part works fine). What I would like to do from there is sort the data into the report sheet by standard category and then also into substandard category going vertically down the sheet. The standard category only need one entry say "standard 3" but there may be many sub standards like "3a, 3b, 3b, 3b, 3c etc. So each sub standard category would need to move in size (number of rows) as to not overwrite the next standard category. I hope this makes sense as is something that excel can handle. I have done a lot of research with no success.
Attachment 659850
Attachment 659851
Attachment 659852

Custom Right Click Menu and Sub-menu (disable inbuilt right click menu item)

$
0
0
This workbook has Module One having Macro to add Menu to Right Click Command.

Code:

Sub RgtMenuOn()
Dim contextMenu As CommandBar
Set contextMenu = Application.CommandBars("Cell")
With contextMenu.Controls.Add(Type:=msoControlButton, Before:=1)
    .OnAction = "DashBoard1"
    .Caption = "DashBoard"
    .Tag = "My_Cell_Control_Tag"
End With
With contextMenu.Controls.Add(Type:=msoControlButton, Before:=2)
    .OnAction = "F"
    .Caption = "FutP"
    .Tag = "My_Cell_Control_Tag"
End With
With contextMenu.Controls.Add(Type:=msoControlButton, Before:=3)
    .OnAction = "FC"
    .Caption = "FC"
    .Tag = "My_Cell_Control_Tag"
End With
With contextMenu.Controls.Add(Type:=msoControlButton, Before:=4)
    .OnAction = "FP"
    .Caption = "FP"
    .Tag = "My_Cell_Control_Tag"
End With
With contextMenu.Controls.Add(Type:=msoControlButton, Before:=5)
    .OnAction = "VC"
    .Caption = "VC"
    .Tag = "My_Cell_Control_Tag"
End With
With contextMenu.Controls.Add(Type:=msoControlButton, Before:=6)
    .OnAction = "VP"
    .Caption = "VP"
    .Tag = "My_Cell_Control_Tag"
End With
With contextMenu.Controls.Add(Type:=msoControlButton, Before:=7)
    .OnAction = "OIC"
    .Caption = "OIC"
    .Tag = "My_Cell_Control_Tag"
End With
With contextMenu.Controls.Add(Type:=msoControlButton, Before:=8)
    .OnAction = "OIP"
    .Caption = "OIP"
    .Tag = "My_Cell_Control_Tag"
End With
With contextMenu.Controls.Add(Type:=msoControlButton, Before:=9)
    .OnAction = "CDoj"
    .Caption = "CDoj"
    .Tag = "My_Cell_Control_Tag"
End With
With contextMenu.Controls.Add(Type:=msoControlButton, Before:=10)
    .OnAction = "PDoj"
    .Caption = "PDoj"
    .Tag = "My_Cell_Control_Tag"
End With
With contextMenu.Controls.Add(Type:=msoControlButton, Before:=11)
    .OnAction = "CDojHam"
    .Caption = "CDojHam"
    .Tag = "My_Cell_Control_Tag"
End With
With contextMenu.Controls.Add(Type:=msoControlButton, Before:=12)
    .OnAction = "PDojHam"
    .Caption = "PDojHam"
    .Tag = "My_Cell_Control_Tag"
End With

End Sub

All Contextmenu Control under Command Bars appears above Cut, Copy etc inbuild Microsoft Office Menu items

Currently it is not grouped and such custom command bars are expanding, hence need to have it under Sub-menu, and seniors help sought.

Help -

How Do I make Three Major CommandBars Say -
1) PrepareData
2) Report Data
3) CustomReport

Such that existing Command Bars appear under item 2) Report Data, and how do I group similar Command bars to call upon Macro that would appear
under item 1) Prepare Data, and 3) CustomReport

So, when I Right Click in Excel, above Cut, Copy etc in-built command bars, only above three items appear at top, and rest of other are grouped under 2) and son on

Is there also a way to hide the default, Cut, Copy, Paste, Insert…., Delete….., Clear Contents…., Filter….., Sort…, Insert Comment…., Format Cell…., Pick from Drop Down List, Define Name…., and Hyperlink….

Something like

Code:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    ' cancel default shortcut menu
    Cancel = True
'''''and call Custom Right Click Menu made above…..only to appear
'this code will be under relevant Worksheet Code window
End Sub

This Custom Right Click Menu should appear have control only in the current workbook only.

Thanks
Attached Files

for loop listing without empty cells

$
0
0
Dear Pros,


Can anyone help me pointing to the mistake in my code?


I want to list the entries from sheet 2 to sheet 1 without any empty cells in between them.

If i run the Code as it is, it keeps listing just the last entry.
If I update lastrow2 it keeps listing all the entries but with empty cells between them..


Can anyone modify it to work properly? (with as litte Change as possible to be able to see what I was doing wrong)


Thank you indeed for your help!


Best regards
Peter
Attached Files

Hyperlink Cell Value to Named Range

$
0
0
Hello and hope you all in peace and healthy.

It is possible macro code for Hyperlink Cell Value to Named Range?.

For example, i have many cell value that can be duplicate in Sheet1. What i trying to do is, Hyperlink them to Named Range.


Sheet1 Cell Value =
A1 = Q.s.1:1 , B1 = Q.s.1:1
A2 = Q.s.1:2 , C1 = Q.s.1:2
A3 = Q.s.1:3 , D1 = Q.s.1:3

Sheet2 Named Range =
A1 = Q.s.1.1
A2 = Q.s.1.2
A3 = Q.s.1.3

I try to Hyperlink Sheet1 Cell A1 and B1 to Named Range Q.s.1.1


Difference between Cell Value and Named Range is , in Cell Value got symbol ":" and in Named Range got symbol "." that i think can help to be a key for Search Function in macro.

Thank You.

vlookup formula using vba

$
0
0
Dear friends
I need help with vlookup formula using vba. what I required automatically copy the formula in next row
For example: =VLOOKUP(C2,'C:\Users\username\Desktop\New folder (2)\New folder (2)\[New Microsoft Excel Worksheet.xlsx]Sheet1'!$A:$B,2,0),this is the formula in D2. Now I want Get automatically in next row using VBA

Export designated sheet as CSV comma delimited

$
0
0
Hi y'all,

I'm trying to export an excel sheet as CSV comma delimited. I've put this code together but I do not get the comma delimitation. Furthermore, some figures contained in the sheet turn into dates in the CSV file. Any ideas? thanks :-)

Code:

Sub saveSheetToCSV()

    Dim myCSVFileName As String
    Dim tempWB As Workbook

    Application.DisplayAlerts = False
    On Error GoTo err

    myCSVFileName = ThisWorkbook.Path & "\" & "CSV-PRAP-" & VBA.Format(VBA.Now, "dd-MMM-yyyy hh-mm") & ".csv"

    ThisWorkbook.Sheets("Upload PRAP eNVenta").Activate
    ActiveSheet.Copy
    Set tempWB = ActiveWorkbook

    With tempWB
    Columns("AF").Delete
    Columns("AE").Delete
    Rows(1).EntireRow.Delete
    .SaveAs Filename:=myCSVFileName, FileFormat:=xlCSV, CreateBackup:=False
    .Close
    End With
err:
    Application.DisplayAlerts = True
    MsgBox ("Done!")
End Sub

Correct attributes for locking a radio button

$
0
0
So I have this code that is tripping up my sub:

Code:

ActiveSheet.shapes.range(Array("rd_Euro6d_y")).locked=true
And a similar piece of code with false. The idea being that under certain circumstances a radio button will no longer be operational. The object does exist and I've even ungrouped it from everything else (had a text box, a group box and rectangle involved in a group before).

The error I get is "Object doesn't support this property or method". I've looked to see why not, and even used the macro recorder to make sure I'm getting the right item / syntax but no joy. Does anyone have any ideas? TIA

Copy limitation to 255 characters - problem

$
0
0
This is my first post, so I would like to welcome everyone :).
I have a problem with VBA code copying text to the selected cell on another sheet.
If the selected text contains 255 characters or less, everything is fine, but if the text contains more than 255 characters, the application displays a prompt containing the error text: Runtime Error 13; type mismatch.
Unfortunately I don't know why :confused:. I am asking for help in clarifying this problem and finding the right solution.
I add a file called example.xlsm presents this problem.
Attached Files

[SOLVED] Create a custom formula (function?) that gives random numbers between a set amount

$
0
0
Hi all,

I've got a spreadsheet where I have to keep typing in random numbers for angle sizes, but I'm getting fed up of keeping typing in =randbetween(15,30) etc etc. So I wanted to create a custom function where I could pick which angle type I Wanted to do and hopefully it'd give me a random number between the size I needed.

I've done this but it just returns 0. Would be appreciative of any help/adjustments please :)

Code:

Function acutevsmall()
Dim Lrandom As Integer
Lrandom = Int((30 - 15 + 1) * Rnd + 15)
End Function

Copy data range based on check box value to another sheet

$
0
0
Hello all

Can anyone help me with the following:

I have a worksheet with the following columns
Bib No. Name GMS ID DOB State Category TS SP TT KE TP IP SR


a. There are about 200 participants of four categories i.e. Boys Under 17, Girls Under 17, Boys Under 21 & Girls Under 21.

b. The above participants can participate in any or all of the events, i.e. TS, SP, TT, KE, TP, IP or SR.

c. I have sheets based on categories and event i.e. TSBU17 for TS event Boys Under 17 and soon.

I am attempting to have a checkbox under each event in every row of participant data and trying to copy data of column A to F in the relevant sheet if the concerned checkbox is clicked and removed if it is unchecked. tried doing some with some help.. attaching workbook for reference, please.

printing contents to a txt file

$
0
0
I need to output the contents in a spreadsheet into a txt file.

The current macro doesn't output it as per the user's request.
It needs to be exactly how it is shown in the Immediate window of VBA.

Capture.PNG

and not like this:

Capture.PNG

does anyone know of a way?

thanks

VBA iserror/vlookup

$
0
0
Hello forum

I have the below code which works but when i get part of a result it wont show a error but will show a 0, how can it be done so that if a error or that it shows a 0 that it will only show a blank cell

Formula:

=IF(ISERROR(VLOOKUP(J30,'(Bulk) Helper Sheet'!$A:$F,6,0)),"",(VLOOKUP(J30,'(Bulk) Helper Sheet'!$A:$F,6,0)))


thanks in advance

Need VBA or Formula for assigning tasks

$
0
0
Hi All,

I am new to the forum so apologies if this is in the wrong place, at work at the start of the month we receive a list of tasks for the month, this list doesn't change during the month and always covers the whole month. I am looking for a way to allocate tasks in an even (or even as possible fashion) between employees. I have attached a sample of the sheet I am currently working with.

A report is run at the beginning of the month which gives me the results in Sheet 1 on attached. I want to be able to copy the information from this report over to a workbook whereby in the statistics sheet I can click allocate and this will allocate an even number of tasks between employees, showing on sheet 1 who the task has been allocated to.

I think I have formulas to cover the rest of the stuff I would need but really could do with a way to allocate an even number of tasks between employees.
Attached Files

[SOLVED] entirerow.delete problem...

$
0
0
Dear Pros,


can you tell me what is the mistake in my code?

Sub löschen()


Code:

Dim i As Long
Dim lasTrow As Long
Dim rAnge As rAnge


lasTrow = ThisWorkbook.Sheets("sheet1").Cells(Rows.Count, 4).End(xlUp).Row
Set rAnge = ThisWorkbook.Sheets("sheet1").Cells(lasTrow, 4)


For i = lasTrow To 1 Step -1


    If Cells(i, 4).Value = "x" Then
    rAnge.Rows(i).EntireRow.Delete
   
    End If
 
   
Next i
End Sub


code is in module "Löschvermerk"

I promise I wont ask any more questions for a while!! :)


thank you indeed
Attached Files

use this base for combinations starting digit = 0000000001111122 to calculate all the poss

F2-F9-Enter / Rpeat

$
0
0
hey everyone im getting really lost im trying to create bulk data for AD and im using excel to create all the creds, I need to convert the cell content from the formula to the results, I discovered the F2 - F9 - Enter method which worked great but after pressing the button 50 or so times I was getting fed up, I have tried looking for macro code to help me but nothing seems to work can you help me I just want to hit the shortcut and it do all my data in C column. please can you help?

FollowHyperLink Vba Anchor Issues

$
0
0
Hello,
I have this simple script to explain the issue I'm running into.

To explain this better I'll use the example

PHP Code:

Sub test()
Dim URL As String
URL 
"https://www.rapidtables.com/web/html/link/html-anchor-link.html#same-page"
ActiveWorkbook.FollowHyperlink Address:=URL

End Sub 

This example loads the URL with https://www.rapidtables.com/web/html...0-%20same-page

Why is the #=%20-%20? Can some assist? Thank you

Huge combination table of queries

$
0
0
Hi,
I'm pretty new to queries but I'm a quick study. I'm making a tool in excel in which retrieves data for the files a user is working on.
Data is in a few of similar tables containing information about the files. I want to retrieve some of that data and combine it with a list of user's assigned files.
Some of the data in the sources is connected in a way that requires first getting a string from one table and match it with another from another table.

Basically I know I could:
A) Query all the files containing the data separately on a hidden sheet. Data could be easily looked up with macros for the user
B) Merge queries to get the information in one table. This is what I tried and I don't know a way to do this without making each merge separately to the last merge and match with a lot of custom columns.
Also in some tables the reference might be on any of 5 columns, and only way I know how to merge the data is with 5 different merges
C) Make queries in vba that retrieve the pieces of data one-by-one from each table for each file. I'm also having problems with this part as some data is in a MySQL-server

Would all of these take tons of time to refresh? Which of the options would be best, or is there a better way?
I'll probably ask a lot of followup questions once I know which path to follow

Thanks

Move columns To Another Sheet Based On Cell Value Excel vba

$
0
0
I have a sheet with some fictional personal data: phone numbers, addresses etc. I have around 200 different persons, So i have made an vba that automatically creates sheets based on the names of the people. And i and quite new to vba and know how to copy data by using

Sheets("Sheet1").Range("A1:O10").Copy Destination:=Sheets("Ark1").Range("A1")

But this only accounts, for that specific sheet destination. How do i based on their names from sheet ("Ark1"). move the data that belongs to the specific persons, from "Ark1". As shown in the linked image, column B is one persons data, C is another etc. The search criteria should be their names, because that is what i define the different sheets as, and their names is in "row2" in the data file "Ark1".

here is the sheet

docs.google.com/spreadsheets/d/1eDm2abizog2akTi3io8WjybyiFu3aKS3oYWwt-9yXaU/edit?usp=sharing


and the code, it does only do well with sorting on columns, were i need soring on rows by names

Code:

Sub SplitSheetDataIntoMultipleWorkbooksBasedOnSpecificColumn()
    Dim objWorksheet As Excel.Worksheet
    Dim nLastRow, nRow, nNextRow As Integer
    Dim strColumnValue As String
    Dim objDictionary As Object
    Dim varColumnValues As Variant
    Dim varColumnValue As Variant
    Dim objExcelWorkbook As Excel.Workbook
    Dim objSheet As Excel.Worksheet
 
    Set objWorksheet = ActiveSheet
    nLastRow = objWorksheet.Range("A" & objWorksheet.Rows.Count).End(xlUp).Row
 
    Set objDictionary = CreateObject("Scripting.Dictionary")
 
    For nRow = 2 To nLastRow
        'Get the specific Column
        'Here my instance is "B" column
        'You can change it to your case
        strColumnValue = objWorksheet.Range("G" & nRow).Value
 
        If objDictionary.Exists(strColumnValue) = False Then
          objDictionary.Add strColumnValue, 1
        End If
    Next
 
    varColumnValues = objDictionary.Keys
 
    For i = LBound(varColumnValues) To UBound(varColumnValues)
        varColumnValue = varColumnValues(i)
 
        'Create a new Excel workbook
        Set objExcelWorkbook = Excel.Application.Workbooks.Add
        Set objSheet = objExcelWorkbook.Sheets(1)
        objSheet.Name = objWorksheet.Name
 
        objWorksheet.Rows(1).EntireRow.Copy
        objSheet.Activate
        objSheet.Range("A1").Select
        objSheet.Paste
 
        For nRow = 2 To nLastRow
            If CStr(objWorksheet.Range("B" & nRow).Value) = CStr(varColumnValue) Then
              'Copy data with the same column "B" value to new workbook
              objWorksheet.Rows(nRow).EntireRow.Copy
 
              nNextRow = objSheet.Range("A" & objWorksheet.Rows.Count).End(xlUp).Row + 1
              objSheet.Range("A" & nNextRow).Select
              objSheet.Paste
              objSheet.Columns("A:B").AutoFit
            End If
        Next
    Next
End Sub

Attached Images
Viewing all 50222 articles
Browse latest View live