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

[SOLVED] vba to insert a specific text till end of row

$
0
0
Hi,
I have a table from Column A to I

In column A, A1 heading and from A2 onwards I have numbers one by one.

In column G, G is heading, and from G2 onwards I need vba to insert specific text "Done" till the end of last row of column A.

please find atatched sample
Attached Files

A Macro to Delete Unwanted Columns

$
0
0
Hi All,

I need help with a simple macro that will delete some columns for me.

In my data set, the only columns that I want to keep is the ones with keywords. I don't want the metrics.

Thanks in advance!
Attached Files

Connect to Access DB, Retrieve Query

$
0
0
I've been reading about the different ways to connect to an access database (implicit vs explicit? ADO Recordset vs Connection Object?) however I could not figure out if I should use any one way over the other.

This is the code that I got to work - ie connect to the DB and do an SQL query. However, I can't figure out how to paste this queried info into my excel sheet. It looks like the Recordset was the way to go? and I can't just tack that onto my existing code below?


Code:

Sub Retrieve_Plans()
 
 
    Dim cn As Object
    Dim rs As Object
    Dim strSql As String
    Dim strConnection As String
    Set cn = CreateObject("ADODB.Connection")
    strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
        "Data Source=C:\Users\bob\Desktop\PLAN333.MDB"
    cn.Open strConnection
 
strSql = "SELECT CLIENT.PLN_CODE AS [Plan Code], ELECTION.PSTATUS AS [Pen Status], ELECTION.RSTATUS AS [RK Status], ELECTION.ASTATUS AS [Adv Status], [PLN_NAME] AS [Plan Name], CLIENT.CNS_CODE, CLIENT.TITLE, CLIENT.First, CLIENT.MI, CLIENT.Last, CLIENT.SUB, CLIENT.SPCNEML, CLIENT.SPHPEML" & _
" FROM CLIENT INNER JOIN ELECTION ON CLIENT.PLN_CODE = ELECTION.PLANCODE" & _
" ORDER BY CLIENT.PLN_CODE, ELECTION.RSTATUS, CLIENT.PLN_CODE;"
 
    Set rs = cn.Execute(strSql)
    'MsgBox rs1.Fields(0) & " rows in strSql"
    Worksheets("Sheet1").Range("A10").Value = rs  '  <----  not working

 
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
 
   
End Sub

Handling 1500 plus check boxes to move selected names to another sheet

$
0
0
Hai guys

I am having an excel to select specific students from sheet source to result
having 1500 plus students in total.What i want is if i select the particular check box
that corresponding name and details should shift to the sheet result sheet in the same order
in which i am selecting.

it seems to be a huge task to assign macro to each and every check box to acheive this task
as massive numbers of checkboxes are here.

Can any one help me..
i have attached a small sample of what i have
Attached Files

#VBa Dinamic Chart line marker #

$
0
0
i want to make chart line marker with dinamic RangeSeries1,2,3 etc and area chart by inputbox selection area
but i want loop series.colection
1.in every series colection add value to series label
2.in every series colection add marker triangle
3.in every series have label name
and i want background chart is none
Attached Files

print PDF

$
0
0
Hello to all,
This macro should funzionasu of Ne00 and Ne01


Code:

Sub stampa_PDF()

Dim sDefPrinter As String

 ActiveSheet.Unprotect "123456"
 
 sDefPrinter = Application.ActivePrinter
    If Application.ActivePrinter = "PDFCreator su Ne00:" = True Then
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
        "PDFCreator su Ne00:", Collate:=True
  Application.ActivePrinter = sDefPrinter
Else
    Application.ActivePrinter = "PDFCreator su Ne01:"
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
        "PDFCreator su Ne01:", Collate:=True
        Application.ActivePrinter = sDefPrinter
End If

 ActiveSheet.Protect "123456"
 
End Sub

but it does not work well, it works only on Ne01.
A help.
max_max

edit userform from date in text box to date picker & text box pick the coressponding data

$
0
0
Dear all
i would like to make some edit in the userform in my attached file
fist in add stock quantity will show userform
1- i want to change the production date from text box to pick up like production date1 (remove production date and make this production date1 instead.
2- add clear bottom like add this part and close form
3- when i press add this part bottom it give me message this reviw data i enter if correct or not (confirmation message )
4- in media type field when i select any one want to show all meaning not show setting only or RODAC but want settling TSA or sda
or Rodac TSA or other selection


second
when i press withdraw quantity will show userform
1-when i select media type field , batch number , automatic show available quantity
field then when i try to insert in withdraw quantity more than available not accept
and show message the quantity more than available


available quantity will get it from Stockdatabase in column F( that corresponding to each type and batch number
Attached Files

Number of times different names show up in Excel

$
0
0
I'm new to Excel macros, and I've been googling around to try to figure out a solution to my problem and it's been driving me crazy.

I would like to make an Excel file with two sheets:
In one sheet, a list of names would be located in a column, e.g. Column A. The list of names will be populated by something else so I have no control over what names will show up.
In the second sheet, I would like to set up a macro that scans the column of names in sheet one and populates Column A with all unique names and Column B with the number of times that name pops up in sheet two.
Then in future iterations, I would like for the macro to be able to scan a whole new list of names and populate Column A with any new unique names and add the number of instances of all the names to the number of instances already present from before in Column B.

Is this at all possible?! I'm going crazy. Any sort of direction or hint would be massively helpful. Thank you!

VBA dynamic charts

$
0
0
I have a range consisting of countries on the Y-axis and years on the X-axis (I am tracking the inflation change over time for each country with a line chart). I want to create a dynamic chart for my sample which will update when a new country is added. The data in the range is linked to another source, hence the number of rows can increase or deacrease. I am happy to use VBA. I don't want to turn the country name into a table and make the dynamic chart based on that, because the legend sign on the chart for empty cells don't disappear. When I turn the whole range into a table and build the chart, it does not do the job either, unless I enter new countries and respective data manually. I tried to use OFFSET&COUNTA, but no luck. The latter works only if I add new date (a new year, new column), but not when I add a new country (new row). This is why I think the only way to do is using VBA.


I will appreciate your help.
Attached Files

Edit VBA code to get data from multiple sheets

$
0
0
Hello everybody
The report indicates the lectures that the student "A" had from multiple sheets by using VBA code.
I want to edit the vba code to include "Shift" ,it can be brought from other sheets from row No. 1
Please your support

#application caller shapes(activesheet.name) #

$
0
0
i have code
Code:

Sub Macro2()
 
    With ActiveSheet.ChartObjects(1).Chart
        ActiveSheet.Shapes("Chart 24").Fill.Visible = msoFalse
        ActiveChart.PlotArea.Select
        Selection.Format.Fill.Visible = msoFalse
    End With
End Sub

' how to make dinamis shapes name ActiveSheet.Shapes("Chart 24")
'become activesheet.shapes(Application.caller) but not run

#application caller shapes(activeshape.name) #

$
0
0
i have code
Sub Macro2()

With ActiveSheet.ChartObjects(1).Chart
ActiveSheet.Shapes("Chart 24").Fill.Visible = msoFalse
ActiveChart.PlotArea.Select
Selection.Format.Fill.Visible = msoFalse
End With
End Sub

' how to make dinamis shapes name ActiveSheet.Shapes("Chart 24")
'become activesheet.shapes(Application.caller) but not run

Run-time error '1004'

$
0
0
I am using a variable to reference the name of a sheet in my workbook. It works in one place, but not in another. I know (KNOW!) that I am missing something simple, but I'm not seeing it. Below are the appropriate lines, copied exactly from my VBA in case there are typos (but the error doesn't happen in compile, only when running).

Code:

'SETUP SCRIPT:
Dim lastrow As Integer
Dim sourcesheet As String
Dim Var1 As Integer
Dim Var2 As Integer
sourcesheet = "Final"
Var1 = 2
Var2 = 2


'WORKING SCRIPT:
lastrow = Worksheets(sourcesheet).Range("B1").End(xlDown).Row
Debug.Print Worksheets("Final").Cells(2, 2)


'NOT WORKING SCRIPT:
Debug.Print Worksheets(sourcesheet).Cells(Var1, Var2)


What am I missing? I get "Run-time error '1004': Application-defined or object-defined error" when I try to run the debug.print line using the variables. I've checked that Var1 and Var2 are holding the right values, that the cell isn't blank (just in case).

I tried the following, but none of these works, either:
Debug.Print Worksheets(sourcesheet).Cells(Var1, Var2).Value
Debug.Print ThisWorkbook.Worksheets(sourcesheet).Cells(Var1, Var2)
Debug.Print ThisWorkbook.Worksheets(sourcesheet).Cells(Var1, Var2).Value

I thought possibly it could be an issue of the subroutine being placed in the wrong module, but all of my VBA is in one Module (Module1, as I wasn't feeling creative).

None of my cells are protected, so that's not the cause.

Thanks for any help you can give me.

recurrence for task list

$
0
0
Hi Champs,

I have a task list for a particular team.

The task list has frequency like below

1. daily task'
2. weekly task
3. monthly task.

i have created a template for Jan 2017 for the task list.

I would like to have a macro if changing the month name, the task list has to repeated for february 2017 with correct frequency like jan 2017?

please help. i have attached a sample.
Attached Files

Current work book .xlsm convert to xlsx work book then mail

$
0
0
Hi,

I need some help in macro to convert the current macro enable work to normal work book & then e-mail. I've to send these to employees, after filling these sheets employee should be able to send in one click. Finally i need .xlsx out file from all employees as file name as there employee ID.

Before e-mail i want a print preview of the sheet, then a msg box to make sure that the file is saved then mail the .xlsx workbook if it's not saved terminate the mail program stating that file is not saved.

Can you please help me in convert the .xlsm to .xlsx work book before it get attached to e-mail. File attachment in mail should have only there employee ID (Emp_ID.xlsx).


Note: I've two sheets in this work books & all these three sheets should be available as it is without any change.
Attached Files

[SOLVED] Sort 3 Columns in a defined range

$
0
0
Hello Experts, need your help in sorting 3 columns..

In a range from A to I, the columns Name (Account & Type & Price) can be anywhere..
below code helps sort 2 columns (Account & Type) finding its name.. how can I add the third column (Price).. how do we modify the code.. I tried but failed on time.. please assist.


Code:

Sub Sort()
Dim sh As Worksheet, cl1 As Long, cl2 As Long, lr As Long, fn1 As Range, fn2 As Range
'Other code here if required
Set sh = Sheets("Sheet1") 'Edit sheet name
lr = sh.Cells.Find("*", , xlFormulas, xlPart, xlByRows, xlPrevious).Row
Set fn1 = sh.Rows(1).Find("Account", , xlValues, xlPart)
    If Not fn1 Is Nothing Then
        cl1 = fn1.Column
    End If
Set fn2 = sh.Rows(1).Find("Type", , xlValues, xlPart)
    If Not fn2 Is Nothing Then
        cl2 = fn2.Column
    End If
If Not fn1 Is Nothing Then
    sh.Range("A1:I" & lr).Sort Key1:=sh.Cells(1, cl1), Order1:=xlAscending, Key2:=sh.Cells(1, cl2), Order2:=xlAscending, Header:=xlYes
Else
    sh.Range("A1:I" & lr).Sort Key1:=sh.Cells(1, cl2), Order1:=xlAscending, Header:=xlYes
End If
'Other code here if required
End Sub

VB script to filter and update value in different sheet

$
0
0
Hi Folks,

I'm new to VB and need guidance with my task in excel.

*I have an excel workbook with multiple sheet (max 6 sheets).

*I need to filter values (pass/fail/in progress)in Sheet 3 ("O" column) which has the name as "Latency" and update the "pass" count in Sheet 1 in a specific row (lets say AE4) and respectively for other filter values.e same code to

Once this is done I can modify the same code to other palces in my worksheet.

explanation about step 2 in VBA code

$
0
0
i could not understand reason behing it, can anybudy explain that why use step 2 in VBA code
check attachment for more detail
Attached Files

VBA code to delete Drawing Objects from a specific Column.

$
0
0
Hi - I am trying to write some VBA code that deletes all Drawing Objects from all cells but only the active column?

I have found code that deletes everything apart from those in the active column, but can't find the reverse.

Example would be where the active cell is cell D7 - So need the code that deletes all drawing objects from Column D, and need to code to be of use in any column in the worksheet based on the active cell.

Any ideas?

Regards

Hans

how to set same code twice in one sheet

$
0
0
hello, the following code below will add date and time to the adjacent columns of A,
im looking for a way to add date and time also to the adjacent columns of D,

Code:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim A As Range, B As Range, Inte As Range, r As Range
    Set A = Range("A:A")
    Set Inte = Intersect(A, Target)
    If Inte Is Nothing Then Exit Sub
    Application.EnableEvents = False
        For Each r In Inte
            If r.Offset(0, 1).Value = vbNullString Then r.Offset(0, 1).Value = Date
            If r.Offset(0, 2).Value = vbNullString Then r.Offset(0, 2).Value = Time
        Next r
    Application.EnableEvents = True
End Sub

in conclusion it would Auto-fill the columns adjacent to A and B with date and time.

many thanks for your time.
Viewing all 50117 articles
Browse latest View live