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

Filter No Longer Works

$
0
0
.
I am puzzled by this error. The following macro was working today and then ... without any edits ... the macro stopped working properly.

This is what I am seeing now after filtering :

Search Error.jpg


This is the same macro that was working a few hours ago :

Code:

Sub FilterAllCols2()

    Application.ScreenUpdating = False
    Dim LastRow As Long, x As Long
    Dim y As Object
    Range("D:D").Columns.TextToColumns DataType:=xlDelimited, FieldInfo:=Array(1, 2)
   
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
       
        For x = 1 To 4
            If ActiveSheet.OLEObjects("TextBox" & x).Object <> "" Then
               
                With Cells(3, 1).CurrentRegion
                    .AutoFilter x, "*" & ActiveSheet.OLEObjects("TextBox" & x).Object.Text & "*"
                End With
            End If
        Next x
   
    Sheet2.Label9.Caption = Application.WorksheetFunction.Subtotal(3, Range("A3:A500000"))
   
    Application.ScreenUpdating = True
 
    Range("A2").Select
End Sub


Except for the EXCEL GREMLINS having infected the workbook .... is there anything needing changing in the macro ?
I have already edited the following line :

Code:

With Cells(3, 1).CurrentRegion
To Cells(4,1) .... and Cells(5,1). Didn't work.


?????


(Maybe the workbook caught Covid-19 ?)

[SOLVED] Make userform always hidden on certain sheets

$
0
0
Hi

I know how to make a userform hide when switching to a sheet(s) where I don't want it available. That part's obvious. But how to make it impossible to open on those sheets? It's late. I'm tired. Maybe this part is obvious too. ;)

Thanks

"Text Import Wizard” in Excel Office 365

$
0
0
How can a you import a “Text Import Wizard” in Excel Office 365 when importing a text file. Excel Office 365 has a manual method to format text input data that is a challenge to change text to columns.

Copy Entire Row Insert Down below if Value found in Column P:P

$
0
0
Hi,
I'm trying to find the value in column > 1, if value found then copy entire row to insert down below but the below did not work. Please help

Code:

Sub Test()
Application.ScreenUpdating = False
Dim cell As Range
For Each cell In Range("P2:P" & Range("A" & Rows.Count).End(xlUp).Row)
If cell.Value > 1 Then
Rows(cell).EntireRow.Copy
Rows(cell + 1).Insert Shift:=xlDown
cell.Offset(1, -11).Value = cell.Offset(1, -11).Value & "EXTRA"
End If
Next cell
Application.ScreenUpdating = True
End Sub

Regards,
tt3

[SOLVED] VBA To Check A Range For Value then Return Error Box

$
0
0
Hi All,

I just want to thank you in advance for any help that you can provide. I have what I think is a relatively straight-forward question, but despite many attempts and much googling, I can't quite get what I'm looking for. Here is my goal.

I would like to run a macro to check a specific column for a specific value, and if it finds something else, have a message box pop up.

To be more specific, here is what I want to have happen:

Check column A for "USA" or "CAN". If Anything else other than "USA" or "CAN" appears, return a message box then exit the code.

Hopefully this isn't too daunting.

Thank you!

Look for the pattern at Column B:C then ==> P.Value = A.Value

VBA Locking Range, if cell date value is less than today.

$
0
0
Greetings, hope all is well!

Trying with VBA to lock range from to B:K, provided that the date of K is less than today.

Can you please help me with a code that will be applied to the active sheet 'ranges'? and whenever new rows are filled?


Thank you very much in advance!
Attached Files

I wanted to use Dir on a OneDrive folder but it doesn’t work!!

$
0
0
Kyle123

Previous post 1256542 refers

I have a macro that when the folder I need to loop through is on a local/network drive uses ...

‘MyFilePath = Dir(myPath & myExtension)

I now need myPath to be a OneDrive shared folder, but as far as I can gather, Dir will not work in that environment ...

But will the code you posted 31/12/2018 in the above post do the equivalent?

Bottom line, I need to loop through every *.xlsm file in the named OneDrive shared folder - open the file, extract the data, close the file, move the file to another OneDrive shared folder - and move to the next file in the named folder until there’s no files left ...

Thanks for any help in getting this to work ...

Macro to copy row to new sheet if specific words entered

$
0
0
I need a macro that if specific words is entered into column A then the entire row will be copied to into a different sheet.

Copy from sheet:
POH Studies or All Other studies

To sheet:
Closed Studies Awaiting Archive

Words to trigger copy:
Closed
Abandoned
Awaiting Close Out

Thank you in advance for your help.
Attached Files

Loop variables and count if contains.

$
0
0
Hello everyone,

I'm very new to VBA and can not figure out how to correctly make this kind of check and calculation.

I have 6 temperatures and 6 states of gas for each temperature. What I need to do is to calculate average for each state. For example: 1- 100C/Vapour, 2 -121C/Liquid, 3 - 132C/Vapour, 4 - 111C/Liquid, 5 - 102C/Vapour, 6 - 108C/Vapour. Vapour - (100+132+102+108)/4, Liquid - (121+111)/2. Is it reasonable to do this using For loop? Stages and temperatures will change. I came to this calculation but it doesn't work. :)

Code:

Sub Button1_Click()

Dim TempTank(1 To 6) As Integer

TempTank(1) = 100
TempTank(2) = 121
TempTank(3) = 132
TempTank(4) = 111
TempTank(5) = 102
TempTank(6) = 108

Dim LVa(1 To 6) As String

LVa(1) = V
LVa(2) = L
LVa(3) = V
LVa(4) = L
LVa(5) = V
LVa(6) = V

Dim i As Integer
Dim TotalLiquid As Integer
Dim TotalVapour As Integer

For i = 1 To 6
    If LVa(i) = L Then
        TotalLiquid = TotalLiquid + TempTank(i)
        Else
        TotalVapour = TotalVapour + TempTank(i)
    End If
Next i

 Call MsgBox(TotalLiquid & " " & TotalVapour)

End Sub

Any help will be much appreciated!

how to disable buttons on a custom ribbon

$
0
0
Hi Guys,

I made a custom ribbon with "custom UI editor", and the ribbon has almost 30 buttons in 3 groups.

I want to disabled some of them if the user want it. In a excel sheet I have the button list and in the next column the user choose if he want enabled or disabled them one by one.
This process should be doing when the excel file is open, so, if the user want enabled a disabled button he can do it but he can see the changes only when he close and open the file again.

on xml for each button I put "getEnabled="ButtonGetEnabled" (the same for all) and "tag="button1" (different name on tag, deppending of the button name)

but I don't know if it is ok and how write the sentences on vba to work it.

I think is so hard or do I tangled to much with it?

thanks for your help

Userform with Autocompletion

$
0
0
Hello!

I´m new in VBA programming and I try to read streets from another sheet to do the autocompletion.

Half way is working with this code:

Code:


Private Sub EingabeStraße_Change()
Dim i As Integer

ListBox1.Clear
ListBox1.Visible = True
l = Me.EingabeStraße.TextLength
For i = 2 To ThisWorkbook.Worksheets("Tabelle2").Range("A1000").End(xlUp).Row

If UCase(Left(ThisWorkbook.Worksheets("Tabelle2").Cells(i, l), Len(EingabeStraße.Text))) = UCase(EingabeStraße.Text) Then
ListBox1.AddItem ThisWorkbook.Worksheets("Tabelle2").Cells(i, l)
End If
Next i

End Sub

Private Sub ListBox1_Change()

End Sub


Private Sub Übernehmen_Click()
ThisWorkbook.Worksheets("Tabelle1").Range("C7").Value = EingabeName.Value
ThisWorkbook.Worksheets("Tabelle1").Range("C9").Value = EingabeAbteilung.Value
ThisWorkbook.Worksheets("Tabelle1").Range("C10").Value = EingabeStraße.Value
ThisWorkbook.Worksheets("Tabelle1").Range("C12").Value = EingabeAnsprechpartner.Value
ThisWorkbook.Worksheets("Tabelle1").Range("C13").Value = EingabeTelefonnummer.Value
End Sub

Private Sub UserForm_Click()
ListBox1.Visible = False
End Sub

Here is an image of the Form:


Form.jpg

The results are shown only corretly when i type just one letter. Not when i type 2.

Another problem is that i can´t select it from the listbox.

Or is there another idea how i can implement autocomplection like Google it does?

For example
Al -> Alpincenter

My code is now only:
A -> Alpincenter
Al -> Nothing

Tracking VBA editor changes

$
0
0
I know Excel has a built-in feature for tracking changes on the front side— in fact I think I've used in the past (I know I have in Word). And I gather through VBA one can create even more sophisticated methods for doing this. What I want and need is a way to track changes made in the coding. I'm still a novice, and sometimes I make changes that have unexpected consequences elsewhere in the coding, and because I'm focused on what I'm doing in the moment, I don't notice that "collateral damage" right away. In fact, my inexperience and my age conspire together, and by the time I do notice, I'm not sure what happened when, and the backtracking becomes extremely difficult.

So: is there a way— through coding, or an Add-in, or an external application— to track these changes? Or do I just need to get in the habit of saving new back-ups at every single step?

Thanks!

Choosing an option value from select tag

$
0
0
Greetings,

I'm trying to optimize a code I'm using for some time now.

The webpage I'm scraping is not public, it creates electronic electricity metering flows. The header value of the flows is created by four drop-down selection fields. The problem is that only if the first field is given a value, only then you get the options for the second, then so on. Here is the snippet of the fields as the page loads and blank to start with:
(please see attached)

If "lstFromCode" is given an option ("R"), then the code changes (as seen in the DOM Explorer if IE):
(please see attached)

and so on... (please note all option values are in "" marks in the code, but it has been lost during copy-paste here) makes me confused. I am able to list the elements and loop through them:
Code:

Set ZPelements = doc.getElementsByTagName("select")
For Each ZPelement In ZPelements
    If ZPelement.Name = "lstToCode" Then
        Debug.Print "found element lstToCode"
        ZPelement.Value = "R"
    End If
Next ZPelement

Immediate window shows the debug message, but I cannot set the value for the first dropdown.

If someone could point me to a solution it would be of great help. The page is heavy with java code. I'm guessing it is something to do with the "onchange" part of the select tag, but I don't know what to look for.

What I am doing now is to manually click these through, which was okay until I have received 10.000+ flows.

Thanks in advance!

Zsolt

Copy opposite value if criteria met

$
0
0
Hi All

I'm after some help with copying a cell value if criteria are met but reverse the value.

My sheet runs like this:

Column A - Figure 1 (numerical value)
Column B - Figure 2 (numerical value)
Column C - Variance (numerical value)
Column D - Variance (percentage value)
Column E - Date
Column F - **output of VBA code**
Column G - Sum of D - F

My criteria is:

IF
Column C >=-10 AND <=10, OR Column D >=-3% AND <=3%
AND Column E < TODAY
THEN
Copy Column C value to Column F but negative/positive opposite value, e.g. 1 would be -1, and -2 would be 2.

I need to apply this code from row 3 to LRow Column A, and overwrite any existing values.

Many thanks!

Macro to delete a row if a column cell starts with X except for X0

$
0
0
I have no experience writing Macros, but I wrote one for my work, and I need to update it now. Originally I had it delete any row that had a column D cell that started with a letter besides S. Now I need the same thing, but I need it to not delete if the cell starts with X0. So far, I can't find a way to do this. Can someone please help me?

Using Hyperlink function to go to a hidden sheet

$
0
0
Hi,

I have been creating a table of contents (ToC) sheet for all my models for some time now using the Hyperlink function. I create a range name for cell A1 in all the workbook's sheets, place those range names in column D of the ToC sheet, and in column E I have a Hyperlinks formula that I copy down that refers to the cells in column D. That Hyperlinks formula displays the exact name of the sheet that contains the range name.

But now, I have clients who are HIDING some of the workbook's sheets and those respective hyperlinks fail.

Is there a VBA solution that will unhide the destination sheet of that specific Hyperlink function and then send the end user to the now unhidden sheet?

Here's the Hyperlink formula from cell E9 referencing the cell containing the range name to its immediate left (D9):

=HYPERLINK("#'"&MID(CELL("filename",INDIRECT(D9)),FIND("]",CELL("filename",INDIRECT(D9)))+1,256)&"'!A1",MID(CELL("filename",INDIRECT(D9)),FIND("]",CELL("filename",INDIRECT(D9)))+1,256)).

Thanks...and hope you and your families are safe in these crazy times,

Lawrence

Clear Row

Copying cells from one sheet to another

$
0
0
Hello, could someone assist me on completing the rest of the table. I got it to work for the first row but then it just stops. Any help would be greatly appreciated.

Here is the code I have so far:

Code:

Sub Button1_Click()
    Dim CastNumber As String
    Dim Assignee As String
    Dim DateWorkedAssigned As String
    Dim FollowUpDeadline As String
    Dim Status As String
    Dim Notes As String
   
    Application.ScreenUpdating = False
   
    Worksheets("Raw Data").Select
    CastNumber = Range("A2")
    Assignee = Range("B2")
    DateWorkedAssigned = Range("C2")
    FollowUpDeadline = Range("D2")
    Status = Range("E2")
    Notes = Range("F2")
   
    Worksheets("CAST Sheet Template").Select
    Worksheets("CAST Sheet Template").Range("A1").Select
   
    If Worksheets("CAST Sheet Template").Range("A1").Offset(1, 0) <> "" Then
    Worksheets("CAST Sheet Template").Range("A1").End(xlDown).Select
    End If
   
    ActiveCell.Offset(7, 1).Select
    ActiveCell.Value = CastNumber
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Assignee
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = DateWorkedAssigned
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = FollowUpDeadline
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Status
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Notes
   
End Sub

Disabling ALT key in Excel

$
0
0
I copy-paste data from browser to excel during most of my day work

For this I follow below method
After copying in prowser I press ALT+TAB to go to excel.

My problem is MOST OF THE TIME it happens while swithcing from Chrome to Excel by pressing ALT+TAB it opens ALT function in excel ( numbers in menu )

This make me irritated. I have to press ESC to close ALT functions and then I can paste.

How to disable ALT function menu ?

In short, how can I make setting such that ALT function MENU does not open or is disabled in Excel
Viewing all 50167 articles
Browse latest View live