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

Shapes ON/OFF from Button (Macro)

$
0
0
Hello all,

I need to create a spreadsheet that allows the users to show/hide the instructions for all columns with a click of a button (please see att). I tried a couple of macros found online but could not adapt them for this.

2014-03-10_15-23-37.jpg

May I ask for help? Is there a macro for this and make it work in a protected spreadsheet?

Thanks in advance,
Tavi

VBA to update Dynamic Range in filter

$
0
0
Hello,

I have below VBA code which I recorded in order to do the selection of filter value.

Code:

ActiveSheet.Range("$A$1:$K$54").AutoFilter Field:=1, Criteria1:=Array( _
        "AS", "ASN"), Operator:=xlFilterValues

But how can I make range in above code to be dynamic? Because every time data would be different so range would wary..
please assist.

Thanks,
Shiva

Compile Error:Syntax Error

$
0
0
hi there,

i am trying to make a webquery on a multiple page website to extract. I got some codings from mr Leith ross and tried to incorporate them with other declaration but I am getting a Syntax error. anyone please? I need help. thanks...
Code:

Sub getthem()

    Dim StartDate  As Variant
    Dim EndDate    As Variant
 
  Set ChangeDateWS = Worksheets("Sheet1")
  Set gather = Worksheets("Sheet4")
 
  StartDate = Format(ChangeDateWS.Range("B5").Value, "yyyy-mm-dd")
  EndDate = Format(ChangeDateWS.Range("B6").Value, "yyyy-mm-dd")
 
  With gather.QueryTables.Add(Connection:= _
      "URL;https://website.site.com/folder/processed_view.jsp?action=find&sdate=" & StartDate & "&edate=" & EndDate &start=0", _
        Destination:=Range("a1"))
 
      .BackgroundQuery = True
      .TablesOnlyFromHTML = True
      .Refresh BackgroundQuery:=False
      .SaveData = True
  End With
End Sub

VBA to sort and filter based on criteria or threshold

$
0
0
Hello,

I'm having a issue to come up with a VBA that can help me filter data starting from row 11 as a header to the last row. This data contains thousand of rows so I need a vba help me sort from a to z for colum E11, F11 and G11 then filter values in column L11 based on the threshold like in between 0 to -100 or 0 to 1000 based on cell B2 and B3 input and filter customer based on cell B4. If cell B2, B3, and B4 are blank then just execute sorting only.

Please help and thank you in advance.

Setting a range...

$
0
0
Hello,

I want to set a range and I'm using the below code, but I'm getting an error in the highlighted code with below message
Code:

Subscript out of range
Code:

Dim dqper as range
Set dqper = Sheets("DPAD").Range("Z23)

Formula pasted works. Same formula in VBA doesn't???

$
0
0
Well... the formula below works fine when I paste it into a cell (F2).

Code:

=IF(OR(G4=":15",G4=":10"),IF(F4<$N$1,"Yes",IF(COUNTIFS('L:\Sports Packages\[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'!$A$7:$A$49,I4,'L:\Sports Packages\[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'!$D$7:$D$49,"<="&J4,'L:\Sports Packages\[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'!$E$7:$E$49,">="&J4,'L:\Sports Packages\[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'!$I$7:$I$49,"<="&(K4/0.5))>0,"Yes","No")),IF(F4<$N$1,"Yes",IF(COUNTIFS('L:\Sports Packages\[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'!$A$7:$A$49,I4,'L:\Sports Packages\[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'!$D$7:$D$49,"<="&J4,'L:\Sports Packages\[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'!$E$7:$E$49,">="&J4,'L:\Sports Packages\[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'!$I$7:$I$49,"<="&K4)>0,"Yes","No")))

However, when inputting the same formula in a macro, I get a debug error when running....

Code:

    ActiveCell.FormulaR1C1 = _
        "=IF(OR(RC[-7]="":15"",RC[-7]="":10""),IF(RC[-8]<R1C14,""Yes"",IF(COUNTIFS('[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'!R7C1:R49C1,RC[-5],'[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'!R7C4:R49C4,""<=""&RC[-4],'[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'!R7C5:R49C5,"">=""&RC[-4],'[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'!R7" & _
        ",""<=""&(RC[-3]/0.5))>0,""Yes"",""No"")),IF(RC[-8]<R1C14,""Yes"",IF(COUNTIFS('[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'!R7C1:R49C1,RC[-5],'[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'!R7C4:R49C4,""<=""&RC[-4],'[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'!R7C5:R49C5,"">=""&RC[-4],'[Shoot For Loot  Minimum Rates 2014 Games.xlsx]Sheet1'" & _
        "C9,""<=""&RC[-3])>0,""Yes"",""No"")))"


Any thoughts, helpful insights appreciated. Thank you!

Connection between Excel and MySql Workbench

$
0
0
Hey, guys!

I've been having a tough time in the last couple days trying to connect an excel file with SQL. I'm using MySQL Workbench and WAMPSERVER and I want to send my queries from excel to the DB on a local host (no need of phpadmin or something like that).

At first, I tried to make a connection directly trough VBA, using codes I found on the internet. Sadly, all my attempts failed.

Later on, I decided to use the Excel automatic option. This means I'm trying to access the SQL Server this way: Click on Data, From Other Sources, From SQL Server.

I've installed like a thousand different plug-ins and I've followed different instructions from an uncountable number of different threads and forums I've found on the internet, but nothing seems to work or I just don't correctly understand how to do it.

Does anybody have an easy, step by step webpage link where the damn connection is explained? Everytime I try to do it I get the following error message:

[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.

Thanks!

Ps: is it fine to post this thread on this particular part of the Forum?

Search through multiple excel files and get data

$
0
0
Hi All,

I'm currently using the following code to "pull" a range data from a closed workbook.

Code:

Private Sub CommandButton1_Click()
With Sheets("Sheet1").Range("H21:H38")
    .Formula = "='C:\Users\[Workbook1.xls]Sheet1'!M35"
    .Value = .Value
End With
End Sub

This works well if I know which workbook and sheet I will be getting the info from. What I would like to do is add a function that searches through a few workbooks looking for a worksheet name that matches a value in a cell in my original workbook.

ie. Workbook 1, cell A1 = "Jelly"

search through excel files for the workbook that contains the worksheet named "Jelly" and then copy a range from that worksheet back to workbook 1.

Does this make sense? Thanks for any help you can provide!

Type 13 Runtime Error Using String Variable in Evaluate Function

$
0
0
I'm a first time contributor to this forum so thanks for letting me join the ranks.

I've got a sub that's evaluating each cell in the range "StoreNames" to see if it is in an adjacent list. If it is not in the list the cell value is added to the MissingStores variable and the counter is increased by one.

Everything works fine except for the "Store" variable in the OR function is giving me a "type mismatch" error. I can see the variable is set correctly (the first store is listed as "American Fork") yet the runtime error breaks the code.

Any advice?


Sub CheckSubmissions()

Dim Store As Range, MissingStores As String, CountMissingStores As Integer

For Each Store In Range("StoreNames")
If Evaluate("=OR(" & Store & " = $J$2:$J$50)") = False Then
MissingStores = MissingStores & Store & ", "
CountMissingStores = CountMissingStores + 1
End If
Next Store

MsgBox "There are " & CountMissingStores & " missing from the directory path. They are " _
& MissingStores

End Sub

Slilder control and conditional popup boxes

$
0
0
I'm helping a colleague, Doug, with his spreadsheet and am stumped. As you'll be able to tell, I really don't know VBA.

The attached spreadsheet has a slider control, that when moved to the right, increases the amount in the adjacent cell in column G.
He would like a popup to appear when the amount increases to a certain number.
I managed to create the popups, but they only work if you physically type in the cell (column G). The slider doesn't trigger the popup.

Does anyone have a solution?

Notes:
There is a macro to reset the numbers in column G to their original numbers. The macro is in Module 1 and is assigned to the "Reset Original Values" button.

The coding for the popups is in the Sheet1 tab.

It was later decided to have a slider for each amount in column G. The attached does not reflect this requested change. Doug can do that later.

Thank you!

Linda

[SOLVED] Change file path name in VBA code based on files location

$
0
0
Hi all,
I have the following code written but I'm wondering if it's possible to modify this to change the red line to update to the path that the workbook is saved in? Meaning that User1\Folder1\ would change but [Workbook1.xlsm]Sheet1'E1 would always be the same. Thanks for any help you can give!


Code:

Private Sub CommandButton1_Click()
' Partner Name
      With Sheets("Data Input").Range("C3")
        .Formula = "='\\PC-SERVER\User1\Folder1\[Workbook1.xlsm]Sheet1'! E1"
          .Value = .Value
      End With
End Sub

Cycle throuhg rows on a sheet

$
0
0
i need the functions to cycle throuhg the rows on each sheet and output data in this format


For Sheet X
For I to Count total rows
output

specific Sheet!A4&CHAR(10)&
Specific Sheet!B4&CHAR(10)&
specific Sheet!C4&CHAR(10)&
IF(ISBLANK(specific sheet!D4),"Det. 2014",Notostraca!D4&CHAR(10)&"Det. R. G. Ahlers 2014"))

anyoen able to help?

Loop through subfolders

$
0
0
Hello,

I have made a code to search for a certain string inside excel files that are in a cetain folder.
I'm ok untll here but th problem is that I also want to search inside excel files that are also on subfolders inside that first folder.

The code needs to look for the strin on the first excel file:
- If found than stop the macro
- If not found than lmove to next file.
- If not found on any files on the main folder, than start searching on subfolders, and so on.

Thank you

counter progressive

$
0
0
Hello,
I hope to explain.
The macro.
Sub CopiaESalvaInPathX ()
included in this workbook saved with a serial number (last number to the right of the name of the saved file).
In the sheet "lavori_esterni" there is a button to change:
ciao max_1
or
ciao max_2
clicking on the button
save sheet
the file is saved in the folder:
ChDir "C: \ Users \ Max \ Desktop \ lavori_esterni" (in my computer)
to display this folder, click on the button:
OPEN FOLDER SHEET SAVED
it is possible that the sequence number is unique to both the file and that every day our numbers start again from 1?
I hope I explained, unfortunately my english I translate with google translator.
I attach the sample file.
Hello and thank you.
max
--------------------------------------------------------------------------------------------------------------------
Ciao,
spero di riuscire a spiegarmi.
La macro.
Sub CopiaESalvaInPathX()
inserita in questo workbook salva con un numero progressivo (ultimo numero a destra del nome del file salvato).
Nel foglio "lavori_esterni" c'è un pulsante per cambiare:
ciao max_1
oppure
ciao max_2
cliccando nel pulsante
save sheet
il file viene salvato nella cartella:
ChDir "C:\Users\massimo\Desktop\lavori_esterni" (nel mio computer)
per visualizzare questa cartella cliccare nel pulsante:
APRI CARTELLA FOGLI SALVATI
è possibile che il numero progressivo sia unico per tutti e due i file e che ogni giorno questo numero ricominci da 1?
Spero di essermi spiegato, purtroppo il mio inglese lo traduco con google traduttore.
Allego il file di esempio.
Ciao e grazie.
max

counter.xls

Routing a spreadsheet for approval

$
0
0
I have a form that I plan to create in excel sheet that needs to be approved by multiple people.

This needs to be sent to the first person then they check approve (through a dropdown) and then hit the "route" button and it sends to the next person on the list and copies the previous and the HR person. I'm not a VB programmer by any means. Is there someone on this forum that has already done this and will be willing to share their file and/or knowledge?

Teresa

VBA - Excel - Disable Share

$
0
0
Hello,

I have some macros in a workbook and when a user turns on the sharing, it disables the macros.

I would like to just disable sharing altogether.

Is there a vba code that can grey out the sharing option?

Setting page breaks with VBA

$
0
0
Hello - I have a document in Excel that constantly changes rows and I need to set a page break with specific criteria, due to the change in rows. Here is what I am trying to do.

The sheet I use has row headers from Row 1 to Row 12 that are to set to print on every page. I want to print only 38 rows worth of data per each sheet, along with the row headers. So basically, that would be 50 rows of data per each sheet if you count the row headers.

The variable is that if there aren't at least 38 rows of data, then I would only need to print 1 page, since the row headers and data wouldn't be more than 50 rows in total.

VBA Code Help Needed

$
0
0
I needed a code that would input the current date and time in the cells in column N whenever changes were made to any cells in the row from columns A to M. For example, if I change a name in cell 6D, then cell 6N would automatically change to the current date and time.

I found a useful code on a forum (maybe here, don't know for certain) and modified it to suit my needs (see below). I am however now getting a debugging error suggesting that the second line that reads "Private Sub Worksheet_Calculate()" is causing an error. I have absolutely no idea what is wrong or how to fix it, and would really appreciate some assistance.

Dim OldVal(365, 13) As Variant
Private Sub Worksheet_Calculate()
Dim i As Integer, m As Integer
Application.EnableEvents = False
For i = 4 To 365
For m = 1 To 13
If Cells(i, m).Value <> OldVal(i - 4, m - 1) Then
OldVal(i - 4, m - 1) = Cells(i, m).Value
Cells(i, 14).Value = Now
End If
Next n
Next i
Application.EnableEvents = True
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long, c As Integer
If Intersect(Target, Range("A4:M365")) Is Nothing Then Exit Sub
r = Target.Row
c = Target.Column
Application.EnableEvents = False
If Cells(r, c).Value <> OldVal(r - 4, c - 1) Then
OldVal(r - 4, c - 1) = Cells(r, c).Value
Cells(r, 14).Value = Now
End If
Application.EnableEvents = True
End Sub

Shape Color Change Based on Value in different sheet

$
0
0
Hello All! I've been hunting around for a solution and can't find exactly what I need. Any help on this would be greatly appreciated.

I'm trying to change the fill color of a shape based on the value of a cell. I've achieved this by using a Worksheet_Change Event, but when the referenced Rang Cell contains a formula linking it to another sheet (=sheet2!E2) it no longer works.

Code:

Private Sub Worksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = False
        If Range("E55") >= Range("E53") Then
        ActiveSheet.Shapes("MeRev").Fill.ForeColor.RGB = RGB(64, 64, 64)
        Else
        ActiveSheet.Shapes("MeRev").Fill.ForeColor.RGB = RGB(192, 80, 77)
   
    End If   
Application.ScreenUpdating = True
End Sub

My Source will need to come from a different Sheet, and cannot be on the same sheet as the shape. Thanks!

Composing Date from 3 Inputs

$
0
0
Hello everybody!
I'm trying to compose a date based on inputs from a userform. The user selects the day, month and year in combo boxes, and I want to place this data on a single cell in the format DD/MM/YYYY. How can I do this?
I appreciate any help!
Viewing all 50121 articles
Browse latest View live